#define _CRT_SECURE_NO_WARNINGS 1
#include <stdio.h>
#include <stdlib.h>
int main()
{
int i = 0;
printf("--------九九乘法表--------\n");
for (i = 1; i < 10; i++)
{
int j = 0;
for (j = 1; j <= i; j++)
printf("%d *%d = %2d ", i, j, i * j);
printf("\n");
}
system("pause");
return 0;
}
优化:打印任意n*n乘法表,使用自定义函数
#define _CRT_SECURE_NO_WARNINGS 1
#include <stdio.h>
#include <stdlib.h>
void multiplication(int n)
{
int i = 0;
int j = 0;
for (i = 1; i <= n; i++)
{
for (j = 1; j <= i; j++)
{
printf("%-2d*%-2d=%3d ", i, j, i*j);
}
printf("\n");
}
}
int main()
{
int n = 0;
printf("打印行:");
scanf("%d",&n);
printf("打印%d*%d乘法表\n",n,n);
multiplication(n);
system("pause");
return 0;
}