1. Write a C++ program that reads two numbers,
a. Compares them and finds the greater number.
b. Checks if both of them are even numbers.
Sample Output 1
Enter the first number: 2
Enter the second number: 4
Number_2 is greater than Number_1
Number_1and Number_2 are both even numbers.
Can someone show me what this program would look like in C++ language?
#include %26lt;iostream%26gt;
using namespace std;
int main()
{
int a,b;
cout%26lt;%26lt;"Enter the first number: ";
cin%26gt;%26gt;a;
cout%26lt;%26lt;"Enter the second number: ";
cin%26gt;%26gt;b;
if (a%26gt;b)
cout%26lt;%26lt;"First Number is Greater\n";
else if(b%26gt;a)
cout%26lt;%26lt;"Second Number is Greater\n";
else
cout%26lt;%26lt;"Numbers are equal\n";
if((a%2==0)%26amp;%26amp;(b%2==0))
cout%26lt;%26lt;"Both Numbers are Even\n";
else
cout%26lt;%26lt;"One or More Numbers are Odd\n";
return 0;
}
Reply:void main
{
int first, second;
cout%26lt;%26lt;Enter first number;
cin%26gt;%26gt;first
cout%26lt;%26lt;Enter second number;
cin%26gt;%26gt;second;
if(first%26gt;second)
cout%26lt;%26lt; first
cout%26lt;%26lt; "is larger than"
cout%26lt;second
else if(second%26gt;first)
cout%26lt;%26lt; second
cout%26lt;%26lt; "is larger than"
cout%26lt;first
else
cout%26lt;%26lt;numbers are equal
if((first%2==0)%26amp;%26amp;(second%2==0))
cout%26lt;%26lt;both are even numbers
}
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment