Print Friendly and PDF
(Odd or Even) Write a program that reads an integer and determines and prints whether it’s odd or even. [Hint: Use the modulus operator. An even number is a multiple of two. Any multiple of two leaves a remainder of zero when divided by 2

Solution: 

#include <iostream>
using std::cin;
using std::cout;
using std::endl;
 
int main()
{
    int x;
 
   cout << "Enter integer :\n";
  cin >> x;
 
  if(x % 2 == 0)
    cout << "The integer is even.\n";
  if(x % 2 == 1)
     cout <<  "The integer is odd.\n";
 
 
   return 0;
}
 
 
zubairsaif

Zubair saif

A passionate writer who loves to write on new technology and programming

Post A Comment:

0 comments: