九九乘法表(循环嵌套)
时间: 2023-10-24 19:07:58 浏览: 143
Sure! 请看下面的代码:
```python
for i in range(1, 10):
for j in range(1, i+1):
print("{} x {} = {}".format(j, i, i*j), end='\t')
print('')
```
这段代码实现了一个九九乘法表的输出,使用了两层循环嵌套,时间复杂度为 O(n^2)。
相关问题
九九乘法表 用循环嵌套实现九九乘法表
以下是使用Python语言实现九九乘法表的代码,其中使用了两层循环嵌套,外层循环控制行数,内层循环控制列数,确保每个数字都被乘到:
```python
for i in range(1, 10):
for j in range(1, i+1):
print('{}*{}={}\t'.format(j, i, i*j), end='')
print()
```
c语言九九乘法表用循环嵌套
以下是C语言实现九九乘法表的代码,使用了两层for循环嵌套,其中外层循环控制行数,内层循环控制列数,同时使用if语句判断只输出上三角部分的乘法表。
```c
#include <stdio.h>
int main() {
for(int i = 1; i < 10; i++) {
for(int j = 1; j <= i; j++) {
printf("%dX%d=%d\t", j, i, i*j);
}
printf("\n");
}
return 0;
}
```
阅读全文
相关推荐















