Write a C++ program to check whether the given number is even or odd.
Program Code 1:
#include<iostream>
using namespace std;
int main()
{
int number;
cout<<"Enter any number to check whether number is even or odd : ";
cin>>number;
cout<<endl;
if(number%2 == 0)
{
cout<<"Entered number is an even number. ";
}
else
{
cout<<"Entered number is an odd number.";
}
return 0;
}
The program code is tested on www.jdoodle.com
Output:
Enter a number to check whether number is even or odd : 5
Entered number is an odd number.
Program Code 2:
#include<iostream>
using namespace std;
int main()
{
int number;
cout<<"Enter any number to check whether number is even or odd : ";
cin>>number;
cout<<endl;
(number%2 == 0)?cout<<" Number is an even.":cout<<" Number is an odd.";
return 0;
}
The program code is tested on www.jdoodle.com
Output:
Enter a number to check whether number is even or odd : 8
Number is an even.
Thanks
Mukesh Rajput
Post A Comment:
0 comments: