Print two calculations in a tidy form.
What to build
Two lines that mix fixed text with calculated values. The line that reads the numbers is written for you.
Requirements
- Print
A + B = Son the first line. - Print
A * B = Pon the second line.
Input
One line with two whole numbers.
Output
Two lines.
Constraints
Each number is from -30000 to 30000.
Example
Input:
3 4
Output:
3 + 4 = 7
3 * 4 = 12
Why it works
printf fills in its format codes from left to right, and each calculation is worked out before it is printed.
Examples
Example 1 · Input
3 4
Expected output
3 + 4 = 7 3 * 4 = 12
Example 2 · Input
10 -2
Expected output
10 + -2 = 8 10 * -2 = -20
Hints
Hint 1
Each %d needs its own value after the text.
Hint 2
A calculation can be written straight in the list of values.
Solution
Show one correct solution (try it yourself first)
#include <stdio.h>
int main(void) {
int a, b;
scanf("%d %d", &a, &b);
printf("%d + %d = %d\n", a, b, a + b);
printf("%d * %d = %d\n", a, b, a * b);
return 0;
}