
Introduction to C++ Programing.
Practice exercises.
1. Write a program that asks the user to enter two numbers, obtains the two numbers
from the user, and prints the sum, product, difference, and quotient of the two
numbers.
2. Write a program that asks the user to enter two integers, obtains the numbers from
the user, and then prints the larger number followed by the words "is larger." If the
numbers are equal, print the message "These numbers are equal."
#include <iostream>
using namespace std;
int main()
{
int num1, num2; // declare variables
cout << "Enter two integers: \t"; // prompt user
cin >> num1 >> num2; // read values from keyboard
// output the results
cout << "The sum is: \t\t" << num1 + num2 << "\n"
<< "The product is: \t" << num1 * num2 << "\n"
<< "The difference is: \t" << num1 - num2 << "\n"
<< "The quotient is: \t" << num1 / num2 << endl;
return 0; //indicate successful termination
}
#include <iostream>
using namespace std;
int main()
{
int num1, num2; // declare variables
cout << "Enter two integers: "; // prompt user
cin >> num1 >> num2; // read values from keyboard
// Compares if values of "num1" and "num2" are equal
if (num1 == num2) // If condition is true, then
cout << "These numbers are equal." << endl;
if (num1 > num2) // If condition is true, then
cout << num1 << " is larger." << endl;
if (num2 > num1) // If condition is true, then
cout << num2 << " is larger." << endl;
return 0; //indicate successful termination
}