Wednesday, 15 April 2020

C++ Question - Even Odd Number

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

Solution:

#include <iostream>
using namespace std;

int main(int argc, char *argv[])
{
 int a;
 cout<<"Enter the Number : ";
 cin>>a;
 (a%2==0)?cout<<"Number is even":cout<<"Number is odd";
 return 0;
}
 
Screenshot: 


No comments:

Post a Comment