Programming

C++ Program to Show Number is Even or Odd Without Using Modulus Operator

Write a program to show an inputted no is even or odd without the use of modulus operator.

Algorithm

  • Start.
  • Read a number,  n
  • a= n-2*(int (n/2)).
  • If a=0 display “The number is even” else display “The number is odd”
  • End

Source Code

#include<iostream>
#include<stdio.h>
#include<conio.h>

using namespace std;

int main()
{
        int n,a;
        cout<<"Enter a number:";
        cin>>n;
        a=n-2*(int(n/2));
        if(a==0)
        cout<<"The number is even"<<endl;
        else
        cout<<"The number is odd"<<endl;
}

Output

even odd

Tuts

About Author

Tutsmaster.org provides tutorials related to tech and programmings. We are also setting up a community for the users and students.