c++ - 如何添加此代码以使用我的 arduino 打印一个完整的三角形?

标签 c++ arduino drawing arduino-c++

它显然只能生成半个三角形,但我不知道如何解决。 我是新来的,老实说我真的不知道如何工作,所以帮助将不胜感激。 我走到这一步,但现在我迷路了:

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

关于c++ - 如何添加此代码以使用我的 arduino 打印一个完整的三角形?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54474686/

相关文章:

c++ - Arduino 打印在大量打印时失败

c++ - 找出我的项目在 Visual Studio 中使用的所有 Boost .lib 文件

c++ - 如何输出数组表中的横排字母

c++ - Fortran C++ 链接库

c++ - boost::scoped_array 上的_BLOCK_TYPE_IS_VALID 错误

java - java的绘图API?

arduino - 使用attachInterrupt时没有匹配函数错误

c++ - 在 Arduino 上使用 RF24Network 发送一个字符数组

algorithm - 避免图中的边相交

c# - 非多行左对齐选项卡控件