Greatest number among three numbers in C
#include<stdio.h>
int main()
{
int num1,num2,num3;
printf("Enter any three number :\t");
scanf("%d\t%d\t%d",&num1,&num2,&num3);
printf("\t Program to find greatest number among three number\n");
if(num1>num2)
{
if(num1>num3)
{
printf("1st number is greater");
}
else
{
printf("3rd number is greater");
}
}
else if(num2>num1)
{
if(num2>num3)
{
printf("2nd number is greater");
}
else
{
printf("3rd number is greater");
}
}
}
output:
Enter any three number : 12
22
33
Program to find greatest number among three number
3rd number is greater
OR
By using nested if in C:
#include<stdio.h>
int main()
{
int num1,num2,num3;
printf("Enter any three number :\t");
scanf("%d\t%d\t%d",&num1,&num2,&num3);
printf("\t Program to find greatest number among three number\n");
if(num1>=num2)
{
if(num1>num3)
{
printf("%d number is greatest",num1);
}
else
{
printf("%d number is greatest",num3);
}
}
else if(num2>=num1)
{
if(num2>num3)
{
printf("%d number is greatest",num2);
}
else
{
printf("%d number is greatest",num3);
}
}
}
Output:
Enter any three number : 12
22
33
Program to find greatest number among three number
33 number is greatest
Comments
Post a Comment