Biggest of Two Numbers Using Ternary Operator: C++


Video tutorial to find the biggest of the two integer numbers in C++, using Ternary Operator.

To find biggest of Two numbers using if-else control structure: Find Biggest of 2 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
24
25
26
#include < iostream .h >
#include < conio .h >
 
void main()
{
 int a, b;
 clrscr();
 
 cout< <"Enter 2 numbers\n";
 cin>>a>>b;
 
 int big;
 
 big = a > b ? a : b;
 
/*
 if( a > b )
  big = a;
 else
  big = b;
*/ 
 cout< <"\nBig is: "<<big;
 
 getch();
}

In this program we take 2 integer values from the user and using ternary operator decide the biggest of 2 numbers.

 big = a > b ? a : b;

if ( a > b ) is true, then value of a will be stored in variable big; else value of b will be stored in big.

Video Tutorial: Biggest of 2 Integer Numbers Using Ternary Operator


[youtube https://www.youtube.com/watch?v=ni2btFMBmlA]

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




Output
Enter 3 no’s
404
302
Big is: 404

Leave a Reply

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