Why not all test cases are passing?

#include
using namespace std;

int main(){

int n;
cin >> n;
int row, col , no;

// Upper Half

for (row = 1; row <=(n+1)/2; row++){
    for (col = 1; col<=(4*(n-row)-12); col ++){
        cout << ' ';
    }
    no = row;
    for (col = 1; col<=row; col ++){
        cout << no << ' ';
        no = no - 1;
    }

    for (col = 1; col<=(4*row - 6); col ++){
        cout << ' ';
    }

    no = 1;
    if (row != 1){
        for (col = 1; col <= row; col ++){
        cout << no << ' ';
        no = no + 1;
    }
    }

    cout << endl;
}



// Lower Half

for (row = (n+1)/2 - 1 ; row>=1; row --){
    for (col = 1; col<=(4*(n-row)-12); col ++){
        cout << ' ';
    }
    no = row;
    for (col = 1; col<=row; col ++){
        cout << no << ' ';
        no = no - 1;
    }

    for (col = 1; col<=(4*row - 6); col ++){
        cout << ' ';
    }

    no = 1;
    if (row != 1){
        for (col = 1; col <= row; col ++){
        cout << no << ' ';
        no = no + 1;
    }
    }
    cout << endl;
}

return 0;

}

i think the code is not readable so view it here https://github.com/aakshatm/cpp-practice/blob/main/PatternDoubleSidedArrow.cpp

Approach:

  1. for upper half:

from i=0 to i<(n/2)

a) print (n-2row-1) spaces
b) print numbers from (col = row+1) to (col >0)
c) print numbers of spaces (2
row -1)
d) print numbers form col=1 to col=row+1

  1. for lower half

for (int row = (n/2-1); row >=0; row–)

  • make the mirror image :bulb: of upper half by using above statement

Mistakes:

  1. you have make your code for specific n=5 but you have make your code of general value of n
  2. your have make other mistakes also try to dry-run the below modified code

Modified Code:

if you have further doubt feel free to ask