Read two numbers and report on them.
What to build
A short report of three calculated lines.
Requirements
- Print
sum S. - Print
difference D, which is the first number minus the second. - Print
product P.
Input
One line with two whole numbers.
Output
Three lines.
Constraints
Each number is from -30000 to 30000.
Example
Input:
3 4
Output:
sum 7
difference -1
product 12
Why it works
cin converts the text into numbers for you, because the variables are int.
Examples
Example 1 · Input
3 4
Expected output
sum 7 difference -1 product 12
Example 2 · Input
10 -2
Expected output
sum 8 difference 12 product -20
Hints
Hint 1
You can read two values with one cin.
Hint 2
A calculation can go straight into the cout chain.
Solution
Show one correct solution (try it yourself first)
#include <iostream>
using namespace std;
int main() {
int a, b;
cin >> a >> b;
cout << "sum " << a + b << endl;
cout << "difference " << a - b << endl;
cout << "product " << a * b << endl;
return 0;
}