C/C++编程学习 - 第22周 ⑧ 九九乘法表

题目链接

题目描述

我们都学过九九乘法表,现在我们将它扩展成12*12的乘法表,请你输出这个乘法表的前N行。

Input
输入一个数N,其中1≤N≤12

Output
输出一个乘法表,每行几个算式之间以空格隔开

Sample Input

5

Sample Output

1*1=1
1*2=2 2*2=4
1*3=3 2*3=6 3*3=9
1*4=4 2*4=8 3*4=12 4*4=16
1*5=5 2*5=10 3*5=15 4*5=20 5*5=25

思路

输入一个数n,输出n行的乘法表。提示:用两重for循环实现。

C++代码:

#include<bits/stdc++.h>
using namespace std;
int main()
{
    
    
	int n;
	while(cin >> n)
	{
    
    
		for(int i = 1; i <= n; i++)
		{
    
    
			for(int j = 1; j <= i; j++)
				cout << j << "*" << i << "=" << j * i << " ";
			cout << endl;
		}
	}
	return 0;
}

猜你喜欢

转载自blog.csdn.net/qq_44826711/article/details/113572746