C++ Program to Check Whether a Given Number is Even or Odd

«
»
This C+ +Program checks if a given integer is odd or even. Here if a given number is divisible by 2 with the remainder 0 then the number is even number. If the number is not divisible by 2 then that number will be odd number.

Here is source code of the C++ program which checks a given integer is odd or even. The C++ program is successfully compiled and run on a Linux system. The program output is also shown below.

  1. /*
  2.  * C++ program to check if given integer is even or odd
  3.  */
  4. #include<iostream>
  5. using namespace std;
  6.  
  7. int main()
  8. {
  9.     int number, remainder;
  10.  
  11.     cout << "Enter the number : ";
  12.     cin >> number;
  13.     remainder = number % 2;
  14.     if (remainder == 0)
  15.         cout << number << " is an even integer " << endl;
  16.     else
  17.         cout << number << " is an odd integer " << endl;
  18.  
  19.     return 0;
  20. }

$ g++ main.cpp
$ ./a.out
Enter the number : 3
3 is an odd integer 
 
$ ./a.out
Enter the number : 10
10 is an even integer

Sanfoundry Global Education & Learning Series – 1000 C++ Programs.

Sanfoundry Certification Contest of the Month is Live. 100+ Subjects. Participate Now!
advertisement
advertisement
If you wish to look at all C++ Programming examples, go to C++ Programs.

advertisement
advertisement
Subscribe to our Newsletters (Subject-wise). Participate in the Sanfoundry Certification contest to get free Certificate of Merit. Join our social networks below and stay updated with latest contests, videos, internships and jobs!

Youtube | Telegram | LinkedIn | Instagram | Facebook | Twitter | Pinterest
Manish Bhojasia - Founder & CTO at Sanfoundry
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He lives in Bangalore, and focuses on development of Linux Kernel, SAN Technologies, Advanced C, Data Structures & Alogrithms. Stay connected with him at LinkedIn.

Subscribe to his free Masterclasses at Youtube & technical discussions at Telegram SanfoundryClasses.