Check a number is even or odd in C++
if else - Question 1
In this question, we will see how to check if a number is an even or odd number in C++ programming using the if else statement. To know more about if else statement click on the if else statement lesson.
Q1) Write a program in C++ to input a number and check it is an even or odd number. An even number is a number which is divisible by 2 and odd number is a number which is not divisible by 2.
Program
#include <iostream>
#include <conio.h>
using namespace std;
int main()
{
int n;
cout<<"Enter a number ";
cin>>n;
if(n%2==0)
{
cout<<"Even Number";
}
else
{
cout<<"Odd Number";
}
return 0;
}
Output
Enter a number 18 Even Number