Tuesday 24 February 2015

Conditional Operator in C++

/*

Conditional Operator or Ternary Operator  ( ?: )
=========================================

Syntax:
=======

Expr1 ? Expr2 : Expr3;

If Expr1 = True Then Execute Expr2
If Expr1 = False Then Execute Expr3

*/
#include<iostream.h>
#include<conio.h>
main()
{
int a;
clrscr();
cout<<"\n Enter Number :";
cin>>a;
cout<<"\n Given Number is :"<<(a>0?"Positive":"Negative");
cout<<"\n Given Number is :"<<(a%2==0?"Even":"Odd");
getch();
}

No comments:

Post a Comment