A conditional operator is also known as ternary operator [exp ? true : false] which can be used to make an either-or choice. Write a C++ program to get a number from the user and find out whether it is odd or even.
Answers
Answered by
0
Answer:
if( test statement)
{
statement block 1
}
else
{
statement block 2
}
Explanation:
program to get a number from the user and find out whether it is odd or even
#include<iostream>
using namespace std;
int main()
{
int n,v;
cout<<" Enter the no. : ";
cin>>n;
v=n%2;
if (v==0)
{
cout <<"The no. is even";
}
else
cout<<"The no. is odd";
return 0;
}
Answered by
1
Answer:
#include <iostream>
using namespace std;
int main()
{
int n;
cin >> n;
if ( n % 2 == 0)
cout << "Even";
else
cout << "Odd";
return 0;
}
Explanation:
Similar questions