繁体   English   中英

如何添加此代码以使用我的 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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM