C++ Program to check even or odd numbers

Simple C Program to check whether given number is even or add: To check even or odd number, divide number by 2 and check remainder. If remainder is 0 then number is even otherwise number is odd. For example number 4 is even because when we divide it with 2, we get remainder 0 and number 5 is odd because when we divide it by 2, we get remainder 1.
 
/* C++ Program to check even or odd numbers */
#include<iostream>
using namespace std;
int main()
{
 int n;
 cout<<"Enter a number: ";
 cin>>n;
 if(n%2==0)
 {
  cout<<n<<" is even number"<<endl;
 }
 else{
  cout<<n<<" is odd number"<<endl;
 }
 return 0;
}
 


Popular posts from this blog