/ leetcodesolve / DSA / Traingle.cpp
swadhinbiswas update on leadcode · 1/19/2025
0b222ff
21 lines · 516 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#include <iostream>
using namespace std;

int main() {
    int n = 4;
    for (int i = 0; i < n; i++) { 
        // Corrected the inner loop condition
        for (int j = 0; j < n - i - 1; j++) { 
            cout << " ";
        }
        for (int j = 1; j <= i + 1; j++) { 
            cout << j;
        }
        // Corrected the inner loop condition and initialization
        for (int j = i; j > 0; j--) { 
            cout << j;
        }
        cout << endl;
    }
    return 0; // Added return statement
}