Monday, November 14, 2011

Even Odd - Ternary Operator

Wap to check whether a number is even or odd using ternary operator .


#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int a;
cout<<"enter a";
cin>>a;
{
a%2==0?cout<<"even":cout<<"odd";
{
getch();
}

*************
OUTPUT:
enter a 42
even
*************

1 comment:

  1. 7 easy ways to find whether a number id odd/even.
    http://www.waytosmart.com/tutorials/c-programming/c-program-to-check-odd-or-even-number-easy-ways.php

    ReplyDelete