使用循环输出九九乘法表
时间: 2024-02-21 12:05:58 浏览: 58
好的,这是使用Python语言输出九九乘法表的代码:
```python
for i in range(1, 10):
for j in range(1, i+1):
print('{}x{}={}\t'.format(j, i, i*j), end='')
print()
```
运行结果如下:
```
1x1=1
1x2=2 2x2=4
1x3=3 2x3=6 3x3=9
1x4=4 2x4=8 3x4=12 4x4=16
1x5=5 2x5=10 3x5=15 4x5=20 5x5=25
1x6=6 2x6=12 3x6=18 4x6=24 5x6=30 6x6=36
1x7=7 2x7=14 3x7=21 4x7=28 5x7=35 6x7=42 7x7=49
1x8=8 2x8=16 3x8=24 4x8=32 5x8=40 6x8=48 7x8=56 8x8=64
1x9=9 2x9=18 3x9=27 4x9=36 5x9=45 6x9=54 7x9=63 8x9=72 9x9=81
```
希望能帮到你!
相关问题
输出九九乘法表 编写一个程序,使用嵌套循环输出九九乘法表用c语言
以下是使用嵌套循环输出九九乘法表的C语言程序:
```c
#include <stdio.h>
int main() {
int i, j;
for (i = 1; i <= 9; i++) {
for (j = 1; j <= i; j++) {
printf("%d*%d=%-2d ", j, i, i * j);
}
printf("\n");
}
return 0;
}
```
该程序使用两个嵌套的循环,外循环控制行数(1到9),内循环控制每一行中的乘法表达式。程序将每一行的结果打印出来,确保每个数字都占用两个字符的宽度,以保持格式整齐。
使用双重循环输出九九乘法表
Sure, here's the code to output the multiplication table for numbers 1 to 9:
```
for i in range(1, 10):
for j in range(1, i+1):
print(f"{i} x {j} = {i*j}", end="\t")
print()
```
This will give you the table in the format:
```
1 x 1 = 1
2 x 1 = 2 2 x 2 = 4
3 x 1 = 3 3 x 2 = 6 3 x 3 = 9
4 x 1 = 4 4 x 2 = 8 4 x 3 = 12 4 x 4 = 16
5 x 1 = 5 5 x 2 = 10 5 x 3 = 15 5 x 4 = 20 5 x 5 = 25
6 x 1 = 6 6 x 2 = 12 6 x 3 = 18 6 x 4 = 24 6 x 5 = 30 6 x 6 = 36
7 x 1 = 7 7 x 2 = 14 7 x 3 = 21 7 x 4 = 28 7 x 5 = 35 7 x 6 = 42 7 x 7 = 49
8 x 1 = 8 8 x 2 = 16 8 x 3 = 24 8 x 4 = 32 8 x 5 = 40 8 x 6 = 48 8 x 7 = 56 8 x 8 = 64
9 x 1 = 9 9 x 2 = 18 9 x 3 = 27 9 x 4 = 36 9 x 5 = 45 9 x 6 = 54 9 x 7 = 63 9 x 8 = 72 9 x 9 = 81
```
阅读全文