九九乘法表
Problem Description
九九乘法表是数学学习的基础,今天我们就来看看乘法表的相关问题。《九九乘法歌诀》,又常称为“小九九”,如下图所示。你的任务是写一个程序,对于给定的一个正整数 n ,输出“九九乘法表”的前 n 行。例如,输入 n 为 9,你的程序的输出将为下图:
Input
输入包含多组测试数据,以 EOF 结束。每组测试数据只包含一个正整数 n (0 < n < 10)。
Output
对于每组测试数据,输出上图所示“九九乘法表”的前 n 行。
Example Input
2
3
Example Output
1*1=1
1*2=2 2*2=4
1*1=1
1*2=2 2*2=4
1*3=3 2*3=6 3*3=9
代码:
#include <stdio.h>
#include <math.h>
int main()
{
int i, n, temp;
while(scanf("%d", &n) != EOF)
{
for(i = 1; i <= n; i++)
{
for(temp = 1; temp <= i; temp++)
{
if(temp == i)
{
printf("%d*%d=%d", temp, i, temp * i);
}
else
{
printf("%d*%d=%d ", temp, i, temp*i);
}
}
printf("\n");
}
}
return 0;
}