Friday, February 4, 2011

Finding Even|Odd numbers

Hi , This post is to show how conditions work ,

For example you wanna make a program which should take a number as an input and should print whether its even or odd , here is the program

#include"iostream.h"
#include"conio.h"

void main()
{
clrscr();

int num;

cin>>num;

if(num%2==0)
{
cout<<"Number is Even";
}
else
{
cout<<"Number is odd";
}

getch();
}

LOGIC : Those numbers whose remainder by dividing with 2 is 0 is an even number otherwise the number is odd.