我如何对此代码进行添加以使用我的 arduino 打印一个完整的三角形
How can I make additions to this code to print a full triangle with my arduino?
它显然只做了半个三角形,但我不知道如何解决这个问题。我是新手,老实说真的不知道如何使用它,所以帮助将不胜感激。我走到了这一步,但现在我迷路了:
void setup()
{
Serial.begin(9600);
Serial.setTimeout(100000); // timeout now is 100 seconds
// read a number from serial port
String s = Serial.readStringUntil(10); // read a line from serial port
int n = s.toInt(); // convert the input string to integer value
for (int i=0; i<n; i++){
for (int j=0; j<i+1; j++){
Serial.print("*" );
}
Serial.print("n");
}
}
void loop(){
}
将
n 替换为行
for(int i = 1, k = 0; i <= rows; ++i, k = 0)
{
for(space = 1; space <= rows-i; ++space)
{
cout <<" ";
}
while(k != 2*i-1)
{
cout << "* ";
++k;
}
cout << endl;
}
这里的输出
https://ideone.com/OPMeO1
相关文章:
- 如何循环打印顶点结构
- 在执行其他功能的同时播放动画(LED矩阵和Arduino/ESP8266)
- 为什么在popback()操作之后,它仍然打印完整的矢量
- 如何在c++中打印目录
- 有一个打印语句的函数是一种糟糕的编程实践吗
- 在线编译器中的分段C++没有打印消息
- Arduino:for/while/if在void setup()或void loop()之前?——错误:之前需要不合格
- 在C++中打印指向不同基元数据类型的指针的内存地址
- 这个指针和内存代码打印是什么?我不知道是打印垃圾还是如何打印我需要的值
- 尝试用纯 c 编程 arduino,得到以下错误:预期的"="、""、";",'asm'或"打印"之前的'__attribute__'|
- Arduino Uno 串行监视器不会打印整个输出;如何解决?
- Arduino:覆盖打印类问题
- 为什么我的串行串行在Arduino IDE上通过串行显示器进行两次打印
- Arduino:在库中计算出的打印值
- 我如何对此代码进行添加以使用我的 arduino 打印一个完整的三角形
- Arduino中的函数和打印函数值的问题
- Arduino 项目需要打印语句才能工作
- 为什么全局对象构造函数只打印 Arduino 中的前 2 个字符
- 如何使用Arduino的Serial.println打印带有浮点数的字符串
- Arduino:LiquidCrystal 无法使用以太网库打印