Video tutorial to find the biggest of the three integer numbers in C++, using if-else control statements and Ternary Operator.
Before watching this video, please make sure to watch and understand this short video: Find Biggest of 3 Numbers: C++
Full Source Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | #include<iostream .h> #include<conio .h> void main() { int a, b, c; clrscr(); cout< <"Enter 3 no's\n"; cin>>a>>b>>c; int big = ( a>b && a>c )?a:(b>c?b:c); /* if( a > b && a > c ) big = a; else if( b > c ) big = b; else big = c; */cout< <"\nAmong "<<a<<" , "<<b<<" , "<<c<<" Biggest is "<<big; getch(); } |
In this program we take 3 integer values from the user and using ternary operator decide the biggest of 3 numbers.
int big = ( a>b && a>c )?a:(b>c?b:c); |
if ( a > b && a > c ) is true, then value of a will be stored in variable big; else ( b > c ? b : c ) will be evaluated. Here, if value of b is greater than c, value of b will be stored in variable big else value of c will be stored in the variable big.
Video Tutorial: Biggest of 3 Integer Numbers
[youtube https://www.youtube.com/watch?v=gfmqT4PwfY0]
Output
Enter 3 no’s
10
20
30
Among 10, 20, 30 Biggest is 30