In this program we will find greater number among two numbers using ternary operator in C++.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
#include<iostream> using namespace std; int main() { int num1,num2; cout<<"Enter 1st Number : "; cin>>num1; cout<<"Enter 2nd Number : "; cin>>num2; //Condition ? True Statements : False Statements; num1>num2 ? cout<<num1<<" is greater." : cout<<num2<<" is greater."; return 0; } |
Output: