#t5. 计算两个数的和差积商
计算两个数的和差积商
Sum, Difference, Product and Quotient
Problem Description
Read two non-negative integers and (with guaranteed), and compute and output their sum, difference, product, and quotient respectively.
This problem uses only the four basic arithmetic operations; you can finish it without any conditional (if) statements.
Input Format
One line containing two non-negative integers and , separated by a single space. is guaranteed.
Output Format
Print four lines in the following format (replace the bracketed parts with the actual values):
[a] + [b] = [a+b]
[a] - [b] = [a-b]
[a] * [b] = [a*b]
[a] / [b] = [a/b]
where:
- The first three lines (sum, difference, product) are integers; print them directly. Note that may be negative — just print it directly, the minus sign comes automatically.
- The fourth line (quotient) must be printed with exactly two decimal places.
Sample Input 1
10 2
Sample Output 1
10 + 2 = 12
10 - 2 = 8
10 * 2 = 20
10 / 2 = 5.00
Sample Input 2
10 3
Sample Output 2
10 + 3 = 13
10 - 3 = 7
10 * 3 = 30
10 / 3 = 3.33
Constraints
, and .
Hint
- Each equation line must be printed with
cout, concatenating the number, the operator, and the spaces exactly as in the sample. - The fourth line is the trap of this problem: writing
a / bbetween twointvalues does integer division and drops the fractional part. Find a way to make the division produce a decimal result. - Keeping two decimal places requires format controls — look up
fixedandsetprecision(in the<iomanip>header). - Check against sample 1:
10 / 2should output5.00, not5.
相关
在以下作业中: