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

0
55

Source Code:

#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;
}

Output:

Enter the Number: 12
Number is even


Enter the Number: 15
Number is odd

LEAVE A REPLY

Please enter your comment!
Please enter your name here