number pattern in cpp

Solutions on MaxInterview for number pattern in cpp by the best coders in the world

showing results for - "number pattern in cpp"
Ernest
06 Sep 2019
1#include <iostream>
2using namespace std;
3
4int main()
5{
6    int rows, count = 0, count1 = 0, k = 0;
7
8    cout << "Enter number of rows: ";
9    cin >> rows;
10
11    for(int i = 1; i <= rows; ++i)
12    {
13        for(int space = 1; space <= rows-i; ++space)
14        {
15            cout << "  ";
16            ++count;
17        }
18
19        while(k != 2*i-1)
20        {
21            if (count <= rows-1)
22            {
23                cout << i+k << " ";
24                ++count;
25            }
26            else
27            {
28                ++count1;
29                cout << i+k-2*count1 << " ";
30            }
31            ++k;
32        }
33        count1 = count = k = 0;
34
35        cout << endl;
36    }
37    return 0;
38}
39
similar questions
queries leading to this page
number pattern in cpp