I think if we check output for input a[4][6]
Then the answer is coming:1 2 3 4 5 6 12 18 24 23 22 21 20 19 13 7 8 9 10 11 17 14 15 16
But the required answer is : 1 2 3 4 5 6 12 18 24 23 22 21 20 19 13 7 8 9 10 11 17 16 15 14
Not getting correct output
My code:#include using namespace std; void spiral_print(int a[][100], int x, int y) { int sc = 0, ec = y - 1, sr = 0, er = x - 1; while (sc <= ec and sr <= er) { for (int j = sc ; j <= ec; j++) { cout << a[sr][j] << " "; } sr++; for (int i = sr; i <= er; i++) { cout << a[i][ec] << " "; } ec–; if (sr < er) { for (int j = ec; j >= sc; j–) { cout << a[er][j] << " "; } er–; } if (sc < ec) { for (int i = er; i >= sr; i–) { cout << a[i][sc] << " "; } sc++; } } } int main() { int r, c; cin >> r >> c; int e=0; int a[100][100]; for (int i = 0 ; i < r; i++) { for (int j = 0 ; j < c; j++) { e++; a[i][j] = e; } } for (int i = 0 ; i < r; i++) { for (int j = 0 ; j < c; j++) { cout << a[i][j] << " "; } cout << endl; } spiral_print(a, r, c); return 0; }