Saturday, 1 September 2012

  • WAP to fnd the possible combinaton.
Example: Enter a number :21
Output:1+2+3+4+5+6
            6+7+8
           10+11

#include <stdio.h>
#include <conio.h>
void main()
{
    int i,no,sum;
    printf("Enter a number");
    scanf("%d",&no);
    for(i=1;i<=no/2;i++)
    {
        sum=0;
        printf("\n");
        for(int j=i;j<no;j++)
        {
         sum=sum+j;
         if(sum==no)
         {
            for(int k=i;k<=j;k++)
            printf("%d +",k);
            break;
                }
            }
         }
         }

WAP to find the greatest of 3 numbers

  • WAP to find the greatest of 3 numbers
#include <stdio.h>
#include <conio.h>
void main()
{
    int a,b,c;
    clrscr();
    printf("Enter three numbers");
    scanf("%d%d%d",&a,&b,&c);
    if(a>b&&a>c)
    printf("%d is greatest",a) ;
    else if(b>a&&b>c)
    printf("%d is greatest",b);
    else
    printf("%d is greater",c);
    getch();
   }

Swapping without 3rd Variable

  • WAP to swap two number without using a third variable.

//WAP to enter two number and swap them.
#include <stdio.h>
#include <conio.h>
void main()
{
    int a,b;
    printf("Enter first numbers");
    scanf("%d",&a);
    printf("Enter second numbers");
    scanf("%d",&b);
    a=a+b-(b=a);
    printf("The first number after swapping is %d and second number is %d",a,b);
    }

Introduction to My Blog

This is Rakesh...My Blog is based on coding of Program On any platform Such as C,C++ and Java. Please post your typical programs with answer or without for solution.