Sunday, 27 October 2013

Odd or Even - C++ Program Sourcecode!

Here is the C++ program to find out whether a give number is odd or even :

/*Please support me by commenting and subscribing and viewing 
my blog frequently! - GeekyCircle Admin */
#include<iostream.h>
#include<conio.h>
void main()
{
    int num; cout<<"Enter the number to be processed : "<<endl;
    cin>>num;
    if(num%2==0)
    {
       cout<<"The number is even!";
    }
    else if(num%2==1)
    {
       cout<<"The number is odd!";
    }
getch();
}
For newer IDEs (like Dev C++) :
/*Please support me by commenting and subscribing and viewing 
my blog frequently! - GeekyCircle Admin */
#include<iostream>
using namespace std;
int main()
{
   int num; cout<<"Enter the number to be processed : "<<endl;
   cin>>num;
   if(num%2==0)
   {
       cout<<"The number is even!";
   }
   else if(num%2==1)
   {
       cout<<"The number is odd!";
   }
return 0;
}
Here is the video tutorial of this program :

The program works on the simple logic that the remainder of an even number when divided by 2 is 0 and that of an odd number is 1. 




No comments:

Post a Comment

You might also like