99乘法表用什么程序

时间:2025-01-29 14:43:20 手机游戏

可以使用多种编程语言来实现99乘法表,以下是一些示例代码:

Python

```python

def print_multiplication_table():

for i in range(1, 10):

for j in range(1, i + 1):

print(f"{j} * {i} = {j * i}", end="\t")

print()

print_multiplication_table()

```

Java

```java

public class Main {

public static void main(String[] args) {

for (int i = 1; i <= 9; i++) {

for (int j = 1; j <= i; j++) {

System.out.printf("%d*%d=%d\t", j, i, i * j);

}

System.out.println();

}

}

}

```

C语言

```c

include

int main() {

int i, j, n;

for (i = 1; i <= 9; i++) {

for (n = 1; n <= 9 - i; n++)

printf(" ");

for (j = 1; j <= i; j++)

printf("%d*%d=%2d ", i, j, i * j);

printf("\n");

}

return 0;

}

```

JavaScript

```javascript

function printMultiplicationTable() {

for (let i = 1; i <= 9; i++) {

for (let j = 1; j <= i; j++) {

console.log(`${j} * ${i} = ${j * i}`, end="\t");

}

console.log();

}

}

printMultiplicationTable();

```

Excel VBA

```vba

Sub 九九乘法表()

Dim ar(1 To 19, 1 To 11)

Range("a:z").Clear

For i = 1 To 19

For j = 1 To 11

If i = j - 1 Or i = j - 2 Then

ar(i, j) = ""

ElseIf i < j Then

ar(i, j) = 23 - j & "×" & 22 - j + i & "=" & (22 - j + i) * (23 - j)

Else

ar(i, j) = j & "×" & i & "=" & i * j

End If

Next j

Next i

[b3].Resize(19, 11) = ar

End Sub

Sub 九九乘法表2()

Dim ar(1 To 29, 1 To 21)

Range("a:z").Clear

For i = 1 To 29

For j = 1 To 21

If i = j - 1 Or i = j - 2 Then

ar(i, j) = ""

ElseIf i < j Then

ar(i, j) = 33 - j & "×" & 32 - j + i & "=" & (32 - j + i) * (33 - j)

Else

ar(i, j) = j & "×" & i & "=" & i * j

End If

Next j

Next i

[b3].Resize(29, 21) = ar

End Sub

```

这些代码示例分别使用Python、Java、C语言、JavaScript和Excel VBA实现了99乘法表的打印。你可以根据自己的需求和熟悉程度选择合适的编程语言来实现。