Write a c++ program to check whether number is odd or even using conditional operator
Answers
Answered by
2
Answer:
this is the correct answer
Attachments:
Answered by
1
Answer:
#include <iostream>
using namespace std;
int main()
{
/* one variable is required*/
/* user have to enter value and it will later be checked*/
int a;
cout<<"enter the number";
cin>>a;
/* using conditional operatorto check the number is odd or even*/
(a % 2 == 0) ? cout << a << " is even." : cout << a << " is odd.";
return 0;
}
The output of the code:-
enter the number 2
it is even
Similar questions