Assignments » Variable, Operator and Expression » Set1 » Solution 10

Write a program to check whether the given number is even or odd (using ? : ternary operator )

    
#include<iostream>
using namespace std;

int main()
{
	int a;
	cout<<"Enter the Number : ";
	cin>>a;
	(a%2==0)?cout<<"Number is even":cout<<"Number is odd";

	
	return 0;
}

SAMPLE RUN # 1

Enter the Number : 56
Number is even

SAMPLE RUN # 2

Enter the Number : 43
Number is odd