"KEEP LEARNING, DON'T STOP."
"KEEP LEARNING, DON'T STOP."
In this section you will learn how to find whether a number is even or odd in c++. We will use if else condition and small mathematic operation to check the even or odd number and we will show the result on output screen. In this program we are taking the input from user.
Let’s suppose a user will input a number as a '6' and then we will perform small mathematic operation on it. With the help if else condition we will check whether a number is even or odd.
2, 4, 6, 8, 10, 12, etc..
1, 3, 5, 7, 8, 9, 11, etc.
#include<iostream.h> #include<conio.h> //EVEN & ODD PROGRAM void main() { clrscr(); int n; cout<<"ENTER A NUMBER:- "; cin>>n; if(n%2 == 0) { cout<<"ENTER NUMBER IS ODD"; } else { cout<<"ENTER NUMBER IS ODD"; } getch(); }
ENTER A NUMBER:- 6 ENTER NUMBER IS EVEN.