用Arduino写一个串口打印乘法表
时间: 2023-04-07 18:01:53 浏览: 189
好的,这个问题我可以回答。以下是用Arduino写的串口打印乘法表的代码:
```
void setup() {
Serial.begin(9600); // 初始化串口通信
}
void loop() {
for (int i = 1; i <= 9; i++) {
for (int j = 1; j <= i; j++) {
Serial.print(j);
Serial.print("x");
Serial.print(i);
Serial.print("=");
Serial.print(i*j);
Serial.print("\t");
}
Serial.println();
}
delay(10000); // 每隔10秒打印一次
}
```
希望这个代码对你有帮助。
相关问题
Arduino用while循环,写乘法表并打印
可以回答这个问题。以下是一个示例代码:
```
int i = 1;
int j = 1;
while (i <= 9) {
while (j <= 9) {
Serial.print(i);
Serial.print(" x ");
Serial.print(j);
Serial.print(" = ");
Serial.println(i*j);
j++;
}
j = 1;
i++;
}
```
这段代码会输出1到9的乘法表。
Arduino用do while循环,写乘法表并打印
可以回答这个问题。以下是示例代码:
```
int i = 1;
int j = 1;
do {
j = 1;
do {
Serial.print(i*j);
Serial.print("\t");
j++;
} while (j <= 9);
Serial.println();
i++;
} while (i <= 9);
```
这段代码使用了两个嵌套的 do while 循环,打印了 1 到 9 的乘法表。
相关推荐
![docx](https://img-home.csdnimg.cn/images/20210720083331.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)