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 https://www.youtube.com/watch?v=2kpHLoBdBjc]
Source Code: C Program To Find Biggest of 3 Numbers using Binary Minus Operator
#include < stdio.h > int main() { int a, b, c; printf("Enter 3 numbers\n"); scanf("%d%d%d", &a, &b, &c); if(a-b > 0 && a-c > 0) { printf("%d is the biggest\n", a); } else { if(b-c > 0) { printf("%d is the biggest\n", b); } else { printf("%d is the biggest\n", c); } } return 0; }
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