PDF free Books Programming Books

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 ********************



Enter A number : 66
66 is an even number

Enter A number : 37
37 is an odd number




Always remember practice makes a person perfect.
You can also use this logic to find about any number whether it is even or odd.



No comments:

Post a Comment