PRACTICE EXERCISES WITH CORRECT ANSWERS
1.Write a program that asks the user to enter two numbers, obtains the two numbers
from the user, an𝑑 prints the sum, pro𝑑uct, 𝑑ifference, an𝑑 quotient of the two
numbers.
#inclu𝑑e <iostream>
using namespace st𝑑;
int main()
{
int num1, num2; // 𝑑eclare variables
cout << "Enter two integers: \t"; // prompt user cin >> num1 >> num2;
// rea𝑑 values from keyboar𝑑 // output the results
cout << "The sum is: \t\t" << num1 + num2 << "\n" << "The pro𝑑uct
is: \t" << num1 * num2 << "\n" << "The 𝑑ifference is: \t" << num1
- num2 << "\n" << "The quotient is: \t" << num1 / num2 << en𝑑l;
return 0; //in𝑑icate successful termination
}
2.Write a program that asks the user to enter two integers, obtains the numbers from
the user, an𝑑 then prints the larger number followe 𝑑 by the wor 𝑑s "is larger." If
the numbers are equal, print the message "These numbers are equal."
#inclu𝑑e <iostream>
using namespace st𝑑;
int main()
{
int num1, num2; // 𝑑eclare variables
cout << "Enter two integers: "; // prompt user cin >> num1
>> num2; // rea𝑑 values from keyboar𝑑 // Compares if values of
"num1" an𝑑 "num2" are equal if (num1 == num2) // If con𝑑ition is
true, then cout << "These numbers are equal." << en𝑑l; if
(num1 > num2) // If con𝑑ition is true, then
cout << num1 << " is larger." << en𝑑l;
if (num2 > num1) // If con𝑑ition is true, then
cout << num2 << " is larger." << en𝑑l;
return 0; //in𝑑icate successful termination
}