Tuesday, August 28, 2007

SERIES 20 TO 1

WAP to print series from 20 to 1

#include

void main ()

{

int a;

clrscr ();

a=20;

while (a>=1)

{

printf ("\n%d",a);

a--;

}

getch ();

}



ODD SERIES

WAP to print Odd numbers from 1 to 20

void main ()

{

int a;

clrscr ();

a=1;

while (a<=20)

{

if (a%2==1)

printf ("\n%d",a);

a++;

}

getch ();

}


PALANDROM NUMBER

WAP to find that number is palandrom or not (121=121)

#include

void main ()

{

int no,r,res,temp=0;

clrscr ();

printf ("Enter Number: ");

scanf ("%d",&no);

r=res=0;

temp=no;

while (no>0)

{

r=no%10;

no=no/10;

res=(res*10)+r;

}

if (temp==res)

printf("Number is Palandrom");

else

printf("Number is not Palandrom");

getch ();

}


QUARDRATIC EQUATION

WAP to find out Quardratic Equation (d=b2-4ac)

void main ()

{

int a,b,c,d;

clrscr ();

printf ("Enter A: ");

scanf ("%d",&a);

printf ("Enter B: ");

scanf ("%d",&b);

printf ("Enter C: ");

scanf ("%d",&c);

d= (b*b)-(4*a*c);

printf ("\nAnswer is %d",d);

getch ();

}


LEAP YEAR

WAP to find out Year is leap or not (IF-ELSE)

void main ()

{

int a;

clrscr ();

printf ("Enter the Year: ");

scanf("%d",&a);

if (a%4==0)

{

printf ("\nYear is Leap");

}

else

{

printf("\nYear is not Leap");

}

getch ();

}


SWAP NUMBERS

WAP to SWAP the three digit number

void main ()

{

int b,r,n,r1,r2;

clrscr ();

printf ("Enter the Value: ");

scanf ("%d",&n);

r=n%10;

n=n/10;

r1=n%10;

n=n/10;

r2=n%10;

n=n/10;

b=(r*100)*(r2*10)+(r2);

printf ("%d%d%d",r,r1,r2);

getch ();

}


INCREMENTAL / DECREMENTAL

WAP to add 1 & subtract 1 from value of a & b

(Incremental & Decremental Operators)

void main ()

{

int a,b;

clrscr();

printf ("Enter A: ");

scanf ("%d",&a);

printf ("Enter B: ");

scanf ("%d",&b);

a++;

b--;

printf ("\nA is %d",a);

printf ("\nB is %d",b);

getch ();

}