Manmohan pattern 2

https://ide.codingblocks.com/s/51652
test case 1 wrong answer

Hi Pratik, it should be 0 instead of o in line number 19.

how to print spaces (which condition to use) in the mountain pattern problem

Hey Pratik, there can be many approaches, here I am sharing my approach for this,

int i, j, k = 1;
    int n;
    cin >> n;
    for (i = 1; i <= n; i++)
    {
        for (j = 1; j <= i; j++)
            {
                cout << k << "  ";
                k++;
            }
        for (j = 1; j <= 2*n - 1 - 2*i; j++)
            cout << "   ";
        for (j = 1; j <= i; j++)
            {
                k--;
                if (k == n)
                    continue;
                cout << k << "  ";
            }
        cout << endl;
    }

how to come up with such a approach

You can count the no. of digits and no. of spaces and then make a possible relation between them.