C++ Program to check whether a number is Even or Odd

 



How to check Even or Odd?

To check a number is even or odd we just have to divide the given number by 2. If number is completely divisible by 2 then it is an even number, or we can say on dividing the number by 2 if reminder comes 0 it is an even number if not then it is an odd number.

Algorithm:

Step 1: Start.

Step 2: Read n.

Step 3: Calculate n%2 and store its value in rem.

Step 4:if rem=0 write Even and go to step 6.

Step 5:if rem!=0 write Odd.

Step 6: Stop.

Program:

 #include <iostream>  
 using namespace std;  
 int main()  
 {  
   int n;  
   cout << "Enter n:";  
   cin >> n;  
   //to check the no. is even or odd  
   //just divide the no. by 2 & check reminder  
   int rem = n % 2;  
   if (rem == 0)  
   cout << "Even";  
   else  
   cout << "Odd";  
   return 0;  
 }  

Output:

Enter n:19
Odd



C++ Program to check whether a number is Even or Odd C++ Program to check whether a number is Even or Odd Reviewed by Beast Coder on January 16, 2021 Rating: 5

No comments:

Powered by Blogger.