This is the another example for the Selection Structure. You know that performs one out of two Statements depending upon the Condition. Here this the Program to find out the number that which one is Even and which one is Odd Number.
#include<iostream.h>
#include<conio.h>
void main()
{
int num;
clrscr();
cout<<"enter the number";
cin>>num;
if(num%2 ==0)
{
cout<<"\n"<<num<<" is an even number";
}
else
{
cout<<"\n"<<num <<" is an odd number";
}
getch();
}
OUTPUT FOR ODD AND EVEN NUMBER WILL BE RESPECTIVELY :
#include<iostream.h>
#include<conio.h>
void main()
{
int num;
clrscr();
cout<<"enter the number";
cin>>num;
if(num%2 ==0)
{
cout<<"\n"<<num<<" is an even number";
}
else
{
cout<<"\n"<<num <<" is an odd number";
}
getch();
}
OUTPUT FOR ODD AND EVEN NUMBER WILL BE RESPECTIVELY :
FOR ODD NUMBER
FOR EVEN NUMBER
No comments:
Post a Comment