Lets write C program to find biggest of 3 numbers, using nested if else statement.
Related Read:
Nested if else Statement In C
Relational Operators In C
Biggest of 3 Numbers Using Ternary Operator: C
C Program To Find Biggest of 3 numbers
#include < stdio.h >
int main()
{
int a, b, c;
printf("Enter 3 numbers\n");
scanf("%d %d %d", &a, &b, &c);
if( a > b && a > c)
{
printf("%d is biggest\n", a);
}
else
{
if( b > c )
{
printf("%d is biggest\n", b);
}
else
{
printf("%d is biggest\n", c);
}
}
return 0;
}
Output 1:
Enter 3 numbers
1
2
3
3 is biggest
Output 2:
Enter 3 numbers
10
18
15
18 is biggest
Here first we check if a is greater than b. If yes, then we display a as big. Else b or c is biggest. So now we check if b is greater than c, if yes, we display b as biggest else c is biggest. Nested if else condition works great for programs like this.
Biggest of 3 numbers: C Program
C Program To Find Biggest of 3 numbers
#include < stdio.h >
int main()
{
int a, b, c, big;
printf("Enter 3 numbers\n");
scanf("%d %d %d", &a, &b, &c);
if( a > b && a > c)
{
big = a;
}
else
{
if( b > c )
{
big = b;
}
else
{
big = c;
}
}
printf("Biggest of 3 number is %d\n", big);
return 0;
}
Output:
Enter 3 numbers
500
550
555
Biggest of 3 number is 555
For list of all c programming interviews / viva question and answers visit: C Programming Interview / Viva Q&A List
For full C programming language free video tutorial list visit:C Programming: Beginner To Advance To Expert