View Code of Problem 57

#include <bits/stdc++.h>
using namespace std;

void draw(int n, int l){
    int length = (l*2-1);
    int nullLength = (n*2 - length) / 2;
    for(int i = 0; i < nullLength; i++)
        cout << ' ';
    for(int i = 1; i <= length / 2 + 1; i++){
        cout << i;
    }
    for(int i = length / 2; i >= 1; i--){
        cout << i;
    }
    cout << endl;
}

int main() {
    int n, i;
    cin >> n;
    for(i = 1; i <= n; i++){
        draw(n, i);
    }
    for(i = n - 1; i >=1; i--){
        draw(n, i);
    }
    return 0;
}

Double click to view unformatted code.


Back to problem 57