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.
/*
* C++ program to check if given integer is even or odd
*/
#include<iostream>
using namespace std;
int main()
{
int number, remainder;
cout << "Enter the number : ";
cin >> number;
remainder = number % 2;
if (remainder == 0)
cout << number << " is an even integer " << endl;
else
cout << number << " is an odd integer " << endl;
return 0;
}
$ 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.
advertisement
advertisement
If you wish to look at all C++ Programming examples, go to C++ Programs.
If you find any mistake above, kindly email to [email protected]Related Posts:
- Check Programming Books
- Check Computer Science Books
- Apply for C++ Internship
- Practice Programming MCQs
- Practice Computer Science MCQs