Star Pyramid

Lab C++ Intermediate 20 points

Read n and print a centred pyramid of n rows: row i has n−i spaces and 2i−1 stars. Use string(count, ch).

Input

One integer.

Output

n rows.

Example

Input

4

Output

   *
  ***
 *****
*******
Sample input available Sample output available
Editor
C++

Hints

string(5, '*') is "*****".

Solution explanation

The string(count, char) constructor replaces an inner loop.

Show solution
#include <iostream>
#include <string>
using namespace std;

int main() {
    int n;
    cin >> n;
    for (int i = 1; i <= n; i++) {
        cout << string(n - i, ' ') << string(2 * i - 1, '*') << "\n";
    }
    return 0;
}
Output
Answer
HOME LEARN COMMUNITY DASHBOARD