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

Mukesh Rajput

Mukesh Rajput

I am a Computer Engineer, a small amount of the programming tips as it’s my hobby, I love to travel and meet people so little about travel, a fashion lover and love to eat food, I am investing a good time to keep the body fit so little about fitness also..

Post A Comment:

0 comments: