1

它显然只制作了半个三角形,但我不知道如何解决这个问题。我对此很陌生,老实说,我真的不知道如何工作,因此将不胜感激。我走了这么远,但现在我迷路了:

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(){

}
4

1 回答 1

1

用行替换 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

于 2019-02-01T07:51:09.733 回答