Tuesday, August 28, 2007

POSITIVE / NEGATIVE

WAP to find out Positive or Negative (IF-ELSE)

void main ()

{

int a;

clrscr ();

printf ("Enter the value of A: ");

scanf("%d",&a);

if (a>=0)

{

printf ("Number is Positive");

}

else

{

printf("Number is Negative");

}

getch ();

}


EVEN OR ODD

WAP to find out Even or Odd number (IF-ELSE)

void main ()

{

int a;

clrscr ();

printf ("Enter the value of A: ");

scanf("%d",&a);

if (a%2==0)

{

printf ("\nNumber is Even");

}

else

{

printf("\nNumber is Odd");

}

getch ();

}




TOTAL SALARY

WAP to find out TOTAL SALARY with (IF-ELSE)

void main ()

{

long int sal,hra,ta,ts;

clrscr ();

printf ("Enter Salary: ");

scanf("%ld",&sal);

if (sal>=5000)

{

hra=sal*.10;

ta=sal*.07;

}

else

{

hra=sal*.08;

ta=sal*.05;

}

ts=sal+hra+ta;

printf ("\n\nTotal Salary is Rs.%ld", ts);

getch ();

}


TOTAL BILL/ DISCOUNT A

WAP to find out Total Bill with discount according to conditions (Ternary Operators)

void main ()

{

int b,dis,n;

clrscr ();

printf ("Enter Bill: ");

scanf ("%d",&b);

dis=(b<500)?(b*.10):(b>=500 &&amp; b<1000)?(b*.15):(b>=1000 && b<=2000)?(b*.20):(b*.25);

n=b-dis;

printf ("Net Bill is %d",n);

getch();

}

BIGGER & EQUAL

WAP to find out Bigger & Equal number from three numbers
(Ternary Operators)

void main ()

{

int a,b,c;

clrscr ();

printf ("Enter the value of A: ");

scanf("%d",&a);

printf ("Enter the value of B: ");

scanf ("%d",&b);

printf ("Enter the value of C: ");

scanf ("%d",&c);

(a>b && a>c)?printf("A is Big"):(b>a && b>c)?printf("B is Big"):(a==b && b==c)?printf("All are Eqaul"):printf("C is Big");

getch ();

}

BIGGER NUMBER 2

WAP to find out Bigger number from two numbers
(Ternary Operators)

void main ()

{

int a,b;

clrscr ();

printf ("Enter the value of A: ");

scanf("%d",&a);

printf ("Enter the value of B: ");

scanf ("%d",&b);

(a>b)? printf ("A is Big"):printf("B is Big");

getch ();

}


BIGGER NUMBER 1

wap to find out bigger number (if-else)

void main ()

{

int a,b;

clrscr ();

printf ("Enter the value of A: ");

scanf("%d",&a);

printf ("Enter the value of B: ");

scanf ("%d",&b);

if (a>b)

{

printf ("A is Greater");

}

else

{

printf("B is Greater");

}

getch ();

}