PDF free Books Programming Books

Showing posts with label Logic for even or odd. Show all posts
Showing posts with label Logic for even or odd. Show all posts

Thursday, 9 February 2017

C++ How to find if the input number is even or odd

C++ Program For Checking whether a number is even or odd

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

void main()
{
int a;
clrscr();  //May not work with all compilers
cout<<"Enter a number :"<<endl;
cin>>a;
if(a%2 != 0)             //divides a/2 and checks if remainder is not equal to zero
{
cout<<a<<" is an odd number"<<endl;
}
else if(a%2 == 0) //ELSE divides a/2 and checks if remainder is equal to zero
{
cout<<a<<" is an even number"<<endl;
}
getch(); 
}

******************* OUTPUT ********************