Read n and print its times table from 1 to 10, one line each, in the form n x i = product.
What to build
A loop that prints one line for each value.
Requirements
- Read
n. - Print ten lines in the form
n x i = product.
Input
One whole number between -1000 and 1000.
Output
Ten lines, for example 7 x 3 = 21.
Constraints
n is between -1000 and 1000.
Example
Input:
7
Output:
7 x 1 = 7
7 x 2 = 14
7 x 3 = 21
7 x 4 = 28
7 x 5 = 35
7 x 6 = 42
7 x 7 = 49
7 x 8 = 56
7 x 9 = 63
7 x 10 = 70
Why it works
The loop variable changes on each pass, so one printf produces all ten rows.
Examples
Example 1 · Input
7
Expected output
7 x 1 = 7 7 x 2 = 14 7 x 3 = 21 7 x 4 = 28 7 x 5 = 35 7 x 6 = 42 7 x 7 = 49 7 x 8 = 56 7 x 9 = 63 7 x 10 = 70
Example 2 · Input
1
Expected output
1 x 1 = 1 1 x 2 = 2 1 x 3 = 3 1 x 4 = 4 1 x 5 = 5 1 x 6 = 6 1 x 7 = 7 1 x 8 = 8 1 x 9 = 9 1 x 10 = 10
Hints
Hint 1
One loop from 1 to 10 is enough.
Hint 2
Match the format exactly: printf("%d x %d = %d\n", n, i, n * i).
Solution
Show one correct solution (try it yourself first)
#include <stdio.h>
int main(void) {
int n;
scanf("%d", &n);
for (int i = 1; i <= 10; i++) printf("%d x %d = %d\n", n, i, n * i);
return 0;
}