You are on page 1of 2

1. Receive a number and determine whether it is odd or even.

#include<iostream.h>
#include<conio.h>
int n;
void main()
{clrscr();
Note: n%2 gives the remainder
cout<<"Enter a number ";
obtained after dividing n with 2.
cin>>n;
if(n%2==0) cout<<n<<" is Even";
else cout<<n<<" is Odd";
getch();
}
2. Obtain two numbers from the keyboard, and determine and display which is the
larger of the two numbers.
#include<iostream.h>
#include<conio.h>
int a,b;
void main()
{ clrscr();
cout<<"Enter any two integers";
cin>>a>>b;
if(a>b) cout<<a<<" is greater than "<<b;
else if(b>a) cout<<b<<" is greater than "<<a;
else cout<<"both are equal";
getch();
}
3. Receive 3 numbers and display them in ascending order from smallest to largest
#include<iostream.h>
#include<conio.h>
int a,b,c;
void main()
{ clrscr();
cout<<"Enter any three integers:";
cin>>a>>b>>c;
if((a<b)&&(b<c)) cout<<a<<" "<<b<<" "<<c;
if((a<c)&&(c<b)) cout<<a<<" "<<c<<" "<<b;
if((b<a)&&(a<c)) cout<<b<<" "<<a<<" "<<c;
if((b<c)&&(c<a)) cout<<b<<" "<<c<<" "<<a;
if((c<a)&&(a<b)) cout<<c<<" "<<a<<" "<<b;

if((c<b)&&(b<a)) cout<<c<<" "<<b<<" "<<a;


getch();
}

You might also like