@CyanCoding/

Pyramid Generator

C++

Create pyramids real easy!

fork
loading
Files
  • main.cpp

This Plugin Crashed!

Error: Error: must not create an existing file {"type":"CREATE_FILE","wid":"0.9238271580439286","path":"main.cpp","file":{"path":"main.cpp","content":{"asEncoding":{"base64":"I2luY2x1ZGUgPGlvc3RyZWFtPgoKdXNpbmcgbmFtZXNwYWNlIHN0ZDsKCmludCBtYWluKCkgewogICAgaW50IHJvd3M7CiAgICBpbnQgYW1vdW50OwogICAgY291dCA8PCAiRW50ZXIgbnVtYmVyIG9mIHJvd3M6ICI7CiAgICBjaW4gPj4gcm93czsKICAgIGNvdXQgPDwgZW5kbDsKICAgIGZvciAoaW50IGkgPSAxLCBrID0gMDsgaSA8PSByb3dzOyArK2ksIGsgPSAwKSB7CiAgICAgICAgZm9yIChpbnQgc3BhY2UgPSAxOyBzcGFjZSA8PSByb3dzLWk7ICsrc3BhY2UpIHsKICAgICAgICAgICAgY291dCA8PCAiICAiOwogICAgICAgIH0KICAgICAgICB3aGlsZSAoayAhPSAyICogaSAtMSkgewogICAgICAgICAgICBjb3V0IDw8ICJ8ICI7CiAgICAgICAgICAgIGFtb3VudCsrOwogICAgICAgICAgICArK2s7CiAgICAgICAgfQogICAgICAgIGNvdXQgPDwgZW5kbDsKICAgIH0gCiAgICByZXR1cm4gMDsKfQ=="},"asBuffer":null},"loaded":true}}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#include <iostream>

using namespace std;

int main() {
    int rows;
    int amount;
    cout << "Enter number of rows: ";
    cin >> rows;
    cout << endl;
    for (int i = 1, k = 0; i <= rows; ++i, k = 0) {
        for (int space = 1; space <= rows-i; ++space) {
            cout << "  ";
        }
        while (k != 2 * i -1) {
            cout << "| ";
            amount++;
            ++k;
        }
        cout << endl;
    } 
    return 0;
}