26 December 2011

C Program to Find Greatest of Four Number using if-elseif-else Statements

1 comment
 Program to Find Greatest of Four Number using if-elseif-else Statements






#include<stdio.h>

void main()
{
int a,b,c,d;
printf("enter the four numbers : ");
scanf("%d%d%d%d",&a,&b,&c,&d);

//if first number is greater than second number
if(a>b)
{
//if first number is greater than third number
if(a>c)
{
//if first number is greater than fourth number
if(a>d)
printf("%d is greatest",a);
else
//fourth number is greater than first number i.e fourth number is also greater than 2nd and 3rd number
printf("%d is greatest",d);
}
//if 3rd number is greater than 1st number i.e 3rd number is also greater than 2nd number
else
{
//if 3rd number is greater than 4rth number
if(c>d)
printf("%d is greatest",c);
else
//if not than 4rth is greatest
printf("%d is greatest",d);
}
}
//if 2nd is greater than 1st number
else
{
if(b>c)
{
if(b>d)
printf("%d is greatest",b);
else
printf("%d is greatest",d);
}
else
{
if(c>d)
printf("%d is greatest",c);
else
printf("%d is greatest",d);
}
}
}

If You Liked This Post Please Take a Time To Share This Post

You May Also Like...

1 comment: