除了Python,还有哪些语言能打印九九乘法表?
时间: 2024-10-16 15:02:53 浏览: 16
除了Python,许多其他编程语言也能打印九九乘法表,包括但不限于:
1. **Java**:
```java
for (int i = 1; i <= 9; i++) {
for (int j = 1; j <= i; j++) {
System.out.print(j + " * " + i + " = " + j * i + "\t");
}
System.out.println();
}
```
2. **JavaScript**:
```javascript
for (let i = 1; i <= 9; i++) {
let row = '';
for (let j = 1; j <= i; j++) {
row += `${j} * ${i} = ${j * i}\t`;
}
console.log(row);
}
```
3. **C++**:
```cpp
#include <iostream>
using namespace std;
int main() {
for (int i = 1; i <= 9; ++i) {
for (int j = 1; j <= i; ++j) {
cout << j << " * " << i << " = " << j * i << '\t';
}
cout << endl;
}
return 0;
}
```
4. **C#**:
```csharp
for (int i = 1; i <= 9; i++)
{
for (int j = 1; j <= i; j++)
{
Console.Write($"{j} * {i} = {j * i}\t");
}
Console.WriteLine();
}
```
以上代码片段展示了在这些语言中的基本实现方式。每种语言有自己的语法,但核心思想都是通过嵌套循环遍历乘法关系。
阅读全文