Multiplication Table
Completed
Read n and print an n×n multiplication table with each number in a width of 4.
Input
One integer (1–12).
Output
n rows.
Example
Input
4
Output
1 2 3 4 2 4 6 8 3 6 9 12 4 8 12 16
Editor
C
Hints
%4d right-aligns each number in 4 characters.
Solution explanation
Fixed-width formatting lines up the columns.
Show solution
#include <stdio.h>
int main() {
int n;
scanf("%d", &n);
for (int r = 1; r <= n; r++) {
for (int c = 1; c <= n; c++) {
printf("%4d", r * c);
}
printf("\n");
}
return 0;
}