Even or Odd in C++


Q. Write a C++ program to check even or odd number.

#include <iostream>   
using namespace std;
  
int main()
{  
	int n;
	cout << "Enter an integer: " ;
	cin >> n;
	if (n%2 == 0){
		cout << "The number " << n <<" is Even number.";
	}
	else{
   		cout << "The number " << n <<" is Odd number.";
	}
    return 0;   
} 

Q. Write an algorithm to check even or odd number.

1. Start
2. Input: Read an integer `n` from the user.
3. Process:
- Compute the remainder when `n` is divided by 2 (`n % 2`).
- If the remainder is 0, then `n` is even.
- Otherwise, `n` is odd.
4. Output:
- If `n` is even, display: "The number n is Even number."
- Else, display: "The number n is Odd number."
5. End 



OnlineTpoint is a website that is meant to offer basic knowledge, practice and learning materials. Though all the examples have been tested and verified, we cannot ensure the correctness or completeness of all the information on our website. All contents published on this website are subject to copyright and are owned by OnlineTpoint. By using this website, you agree that you have read and understood our Terms of Use, Cookie Policy and Privacy Policy.