2021年1月4日星期一

How to print inverted half-star pyramid pattern next to each other?

I want to display an inverted half-star pyramid pattern next to each other.Here's the desired output

And here's my code:

#include <iostream>  using namespace std;  int main()  {    int n, x, y, k;    cout << "Enter Number of Rows: ";    cin >> n;    for (x = n; x >= 1; x--)    {          for (y = 1; y <= x; y++)          {                if (y <= x)                      cout << "*";                else                      cout << " ";          }          for (y = n; y >= 1; y--)          {                if (y <= x)                      cout << "*";                else                      cout << " ";          }          cout << "\n";    }    return 0;  

}

Here's the output I got after running the code. The number of rows desired is 10. After running my code, the output isn't like what I expected. Please tell me how to make it right. Thank you.

https://stackoverflow.com/questions/65572704/how-to-print-inverted-half-star-pyramid-pattern-next-to-each-other January 05, 2021 at 11:08AM

没有评论:

发表评论