C Program To Find Biggest of 3 Numbers using Binary Minus Operator


Lets write a simple C program to find biggest of three numbers using binary minus operator.

Related Read:
if else statement in C
Nested if else Statement In C

Logic To Find Biggest of 3 Numbers using Binary Minus Operator

If user enters a = 1, b = 2, c = 3;

We check if a – b > 0 and a – c > 0
i.e., 1 – 2 > 0 and 1 – 3 > 0
=> -1 > 0 and -2 > 0 (Both these conditions are false).
So a is not the biggest.

In else block we check if b – c > 0
=> 2 – 3 > 0
=> -1 > 0 (which is false)
So b is not the biggest.

In that case whatever number present in variable c is biggest.

Video Tutorial: C Program To Find Biggest of 3 Numbers using Binary Minus Operator



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

Source Code: C Program To Find Biggest of 3 Numbers using Binary Minus Operator

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

Output 1:
Enter 3 numbers
1
2
3
3 is the biggest

Output 2:
Enter 3 numbers
10
30
20
30 is the biggest

Output 3:
Enter 3 numbers
100
50
75
100 is the biggest

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 *