You are on page 1of 8

Q1: Take two number from the user and display the greater

number.
#include <iostream>
using namespace std;
int main()
{
int num1, num2;

cout<<"Please enter the first number :";


cin>>num1;
cout<<"Please enter the second number :";
cin>>num2;

if(num1>num2)
{
cout<<"The greater number is: "<<num1;
}
else

{
cout<<"The Greater number is:"<<num2;
}
return 0;
}

Screen Output:
Please enter the first number: 10
Please enter the second number:20
The greater number is:20
Screen Output:
Please enter the first number: 78
Please enter the second number:45
The greater number is:78

1
Q2: Take a number from user and tell it that multiple of two or not.
#include <iostream>
using namespace std;
int main()
{
int num;

cout<<"Please enter the number : ";


cin>>num;

if(num%2==0)
{
cout<<"The number is multiple of two";
}
else
{
cout<<"The number is not the multiple of two ";
}
return 0;
}

Screen Output:
Please enter the number:100
The number is multiple of two

Screen Output:
Please enter the number:75
The number is not multiple of two

2
Q3: Input two number from the user, take that sum and display that
the sum is greater than 100 or not.
#include <iostream>
using namespace std;
int main()
{
int num1, num2;
cout<<"Please enter the first number";
cin>>num1;
cout<<"Please enter the second number";
cin>>num2;
int sum=num1+num2;
if(sum>100)
{
cout<<"The sum of two number is greater than hundred";
}
else
{
cout<<"The sum of two number is less than hundred";
}
return 0;
}

Screen Output:
Please enter the first number: 45
Please enter the second number: 65
The sum of two number is greater than hundred

Screen Output:
Please enter the first number: 12
Please enter the second number: 36
The sum of two number is less than hundred

3
Q4: Input two number from the user, multiply them and tell their
the answer is even or odd.
#include <iostream>
using namespace std;
int main()
{
int num1, num2;
cout<<"Please enter the first number: ";
cin>>num1;
cout<<"Please enter the second number: ";
cin>>num2;
int ans=num1*num2;
if(ans%2==0)
{
cout<<"The answer is "<<ans<< " which is even";
}
else
{
cout<<"The answer is "<<ans<< " which is odd";
}
return 0;
}

Screen Output:
Please enter the first number: 28
Please enter the second number: 41
The answer is 1148 which is even
Screen Output:
Please enter the first number: 7
Please enter the second number: 3
The answer is 21 which is odd

4
Q5: Input a number from the user, if number is odd… make it even
and display message on screen “number has been made even”
otherwise if number is already even… your program display
message that number is already even.
#include <iostream>
using namespace std;
int main()
{
int num;
cout<<"Please enter the number you want to make even: ";
cin>>num;
if(num%2==0)
{
cout<<"This number is already an even number, Please enter another number";
}
else
{
int result=num+1;
cout<<"The result is: "<<result<<" as you can see number has been made
even";

}
return 0;
}

Screen Output:
Please enter the number you want to make even: 99
The result is: 100 as you can see number has been made even

Screen Output:
Please enter the number you want to make even: 78
This number is already an even number, Please enter another number

5
6
7
8

You might also like