Monday, January 4, 2010

Program to find whether given no is even or odd

#include
#include

void main()
{
int n;
clrscr();
printf("enter any no: ");
scanf("%d",&n);
if(n%2==0)
printf("no is even");
else
printf("no is odd");
getch();
}



Output:
enter any no: 5
no is odd

Program to find that entered year is leap year or not.

#include
#include

void main()
{
int n;
clrscr();
printf("enter any year: ");
scanf("%d",&n);
if(n%4==0)
printf("year is a leap year");
else
printf("year is not a leap year");
getch();
}


Output:
enter any year: 1947
year is not a leap year
 

Program to show the use of conditional operator: Program to show the use of conditional operator: Program to show the use of conditional operator: Program to show the use of conditional operator: Program to show the use of conditional operator:


#include
#include

void main()
{
clrscr();
printf("enter value for a & b: ");
scanf("%d%d",&a,&b);
(a>b)?printf("a is greater"):printf("b is greater");
getch();
}






Output:

enter value for a & b: 5
7
b is greater



Biggest among three number


#include
#include

void main()
{
int a,b,c;
clrscr();
printf("enter value of a, b & c: ");
scanf("%d%d%d",&a,&b,&c);
if((a>b)&&(a>c))
printf("a is greatest");
if((b>c)&&(b>a))
printf("b is greatest");
if((c>a)&&(c>b))
printf("c is greatest");
getch();
}



Output:
enter value for a, b& c: 5
7
4
b is greatest

 

Program to find gross salary: Program to find gross salary: Program to find gross salary: Program to find gross salary: Program to find gross salary: Program to find gross salary:

#include
#include

void main()
{
int gs,bs,da,ta;
clrscr();
printf("enter basic salary: ");
scanf("%d",&bs);
da=(10*bs)/100;
ta=(12*bs)/100;
gs=bs+da+ta;
printf("gross salary=%d",gs);
getch();
}

Program to reverse a given number:


#include
#include

void main()
{
int n,a,r=0;
clrscr();
printf("enter any no to get its reverse: ");
scanf("%d",&n);
while(n>=1)
{
a=n%10;
r=r*10+a;
n=n/10;
}
printf("reverse=%d",r);
getch();
}

Program to show swap of two no’s without using third variable.


#include
#include

void main()
{
int a,b;
clrscr();
printf("enter value for a & b: ");
scanf("%d%d",&a,&b);
a=a+b;
b=a-b;
a=a-b;
printf("after swapping the value of a & b: %d %d",a,b);
getch();
}