write a C program to print the standard multiplication table
Here is a C program that prints the standard multiplication table:
#include <stdio.h>
int main() {
int i, j;
printf("Multiplication Table:\n");
// Print the top row (header)
printf(" x |");
for (i = 1; i <= 10; i++) {
printf("%4d", i);
}
printf("\n");
printf("----");
for (i = 1; i <= 10; i++) {
printf("----");
}
printf("\n");
// Print the multiplication table
for (i = 1; i <= 10; i++) {
printf("%2d |", i);
for (j = 1; j <= 10; j++) {
printf("%4d", i * j);
}
printf("\n");
}
return 0;
}
This program uses nested loops to iterate through the rows and columns of the multiplication table and prints the result for each combination. The first loop is used for rows (i) and the second loop is used for columns (j). The format specifier "%4d" is used to ensure each number is printed with a width of 4 characters, giving the table a neat and organized appearance
原文地址: http://www.cveoy.top/t/topic/hEiq 著作权归作者所有。请勿转载和采集!