Showing posts with label how to write if else statement in one line. Show all posts
Showing posts with label how to write if else statement in one line. Show all posts

Monday, 2 February 2015

Ternary operator in C++

Structure of the Problem Requirements 

Ternary operator used in C++ programming to write if else statement a program in one line. There is no difference between simple if else condition which is very common in programming and ternary operator (if else condition), compiler treat both code same but programmer used ternary operator to save the keystrokes.

Source Code

#include<iostream>
using namespace std;
int main ()
{
cout<<"\t \t \t LEP Tutorials \n \n \n ";
int z,x ,y ;
cout<<" Enter Your Number : ";
cin>>x;
cout<<endl;
cout<<" Enter Your Number : ";
cin>>y;
cout<<endl;
z = (x > y) ? x : y;
cout<<" The Greatest Number is : "<<z;
return 0;
}

Output of the Program

Ternary operator in C++