Use of Nested if condition
#include <stdio.h>
// #include <string.h>
int main()
{
// find maximum number between 3 numbers
int a, b, c;
printf("Enter 3 distinct numbers seperated by space: ");
scanf("%d", &a);
scanf("%d", &b);
scanf("%d", &c);
if (a > b)
{
// a > b => b a
if (a > c)
{
// a > b , a > c => b c a
printf("1st is the greatest no.");
}
else
{
// a > b , a < c => b a c
printf("3rd is the greatest no.");
}
}
else
{
// a < b => a b
if (b < c)
{
// a < b, b < c => a b c
printf("3rd is the greatest");
}
else
{
// a < b, b > c => a c b
printf("2nd no. is greatest");
}
}
return 0;
}
No comments:
Post a Comment