We assume you have basic knowledge of c++ programming language. In this program, we have used the if…else statement to check even or odd, entered by the user during program execution.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | #include <iostream> using namespace std; int main() { int n; cout << "Enter an integer: "; cin >> n; if ( n % 2 == 0) cout << n << " is even."; else cout << n << " is odd."; return 0; } |
#first try
Enter an integer: 12
12 is even.
#second try
Enter an integer: 51
51 is odd.
If you like FreeWebMentor and you would like to contribute, you can write an article and mail your article to [email protected] Your article will appear on the FreeWebMentor main page and help other developers.
Article Tags: c program, c programs, c++ program to check odd and even numbers, C++ Tutorial, odd and even number programs