Stay Tuned!

Subscribe to our newsletter to get our newest articles instantly!

C++ Programming

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

Hierarchical Inheritance

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

Avatar

Tuts

About Author

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

You may also like

program to find leap year
C++ Programming

C++ Program to Find Leap Year by Using Function

  • March 3, 2016
Write a program to find if the inputted year is a leap year or not by using the concept of