Biggest of 3 Numbers: C


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

  1.    
  2. #include < stdio.h >  
  3.   
  4. int main()  
  5. {  
  6.     int a, b, c;  
  7.   
  8.     printf("Enter 3 numbers\n");  
  9.     scanf("%d %d %d", &a, &b, &c);  
  10.   
  11.     if( a > b && a > c)  
  12.     {  
  13.         printf("%d is biggest\n", a);  
  14.     }  
  15.     else  
  16.     {  
  17.         if( b > c )  
  18.         {  
  19.             printf("%d is biggest\n", b);  
  20.         }  
  21.         else  
  22.         {  
  23.             printf("%d is biggest\n", c);  
  24.         }  
  25.     }  
  26.   
  27.     return 0;  
  28. }  

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


[youtube https://www.youtube.com/watch?v=iy–Q0cLnfc]

YouTube Link: https://www.youtube.com/watch?v=iy–Q0cLnfc [Watch the Video In Full Screen.]


C Program To Find Biggest of 3 numbers

  1.    
  2. #include < stdio.h >  
  3.   
  4. int main()  
  5. {  
  6.     int a, b, c, big;  
  7.   
  8.     printf("Enter 3 numbers\n");  
  9.     scanf("%d %d %d", &a, &b, &c);  
  10.   
  11.     if( a > b && a > c)  
  12.     {  
  13.         big = a;  
  14.     }  
  15.     else  
  16.     {  
  17.         if( b > c )  
  18.         {  
  19.             big = b;  
  20.         }  
  21.         else  
  22.         {  
  23.             big = c;  
  24.         }  
  25.     }  
  26.   
  27.     printf("Biggest of 3 number is %d\n", big);  
  28.   
  29.     return 0;  
  30. }  

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

Leave a Reply

Your email address will not be published. Required fields are marked *