"C Program to Print Multiplication Table - Simple & Efficient Code"\n\nHere is a C program that prints the standard multiplication table:\n\nc\n#include <stdio.h>\n\nint main() {\n int i, j;\n\n printf(\"Multiplication Table:\n\");\n\n // Print the top row (header)\n printf(\" x |\");\n for (i = 1; i <= 10; i++) {\n printf(\"%4d\", i);\n }\n printf(\"\n\");\n printf(\"----\");\n for (i = 1; i <= 10; i++) {\n printf(\"----\");\n }\n printf(\"\n\");\n\n // Print the multiplication table\n for (i = 1; i <= 10; i++) {\n printf(\"%2d |\", i);\n for (j = 1; j <= 10; j++) {\n printf(\"%4d\", i * j);\n }\n printf(\"\n\");\n }\n\n return 0;\n}\n\n\nThis 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.

C Program to Print Multiplication Table - Simple & Efficient Code

原文地址: https://www.cveoy.top/t/topic/pnnk 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录