In this example, We take three integer values as input and check which number is largest or greatest among them.
For finding greatest or largest number we are going to use if...else in and nested if...else.
Example :
#include <stdio.h>
void main()
{
int num1, num2, num3;
printf("Enter three integer number :: ");
scanf("%d %d %d", &num1, &num2, &num3);
printf("num1 = %d\tnum2 = %d\tnum3 = %d\n", num1, num2, num3);
if (num1 > num2)
{
if (num1 > num3)
{
printf("num1 is the greatest among three \n");
}
else
{
printf("num3 is the greatest among three \n");
}
}
else if (num2 > num3)
printf("num2 is the greatest among three \n");
else
printf("num3 is the greatest among three \n");
}
Output :
//Output :- 1
Enter three integer number :: 100 200 300
num1 = 100 num2 = 200 num3 = 300
num3 is the greatest among three
//Output 2
Enter three integer number :: 200 250 200
num1 = 200 num2 = 250 num3 = 200
num2 is the greatest among three
Ask anything about this examples