View Code of Problem 53

#include <iostream>

using namespace std;

const int MAXN = 17;

char arr[MAXN][MAXN];

int main() {
    int n;
    while(cin >> n) {
        int middle = n - 1;
        int width = 2 * n - 1;
        int height = 2 * n - 1;
        for (int i = 0; i < n; ++i) {
            for (int j = 0; j < width; ++j) {
                if (j >= middle - i && j <= middle + i){
                    arr[i][j] = '*';
                    arr[height - i - 1][j] = '*';
                }
                else{
                    arr[i][j] = ' ';
                    arr[height - i - 1][j] = ' ';
                }
            }
        }

        for (int i = 0; i < height; ++i) {
            for (int j = 0; j < width; ++j) {
                cout << arr[i][j];
            }
            cout << endl;
        }
    }

}

Double click to view unformatted code.


Back to problem 53