Spiralprint 2-D array

#include
using namespace std;
void spiralprint(int a[][1000], int m, int n) {
int start_row = 0;
int end_row = m - 1;
int start_col = 0;
int end_col = n - 1;

while (start_row <= end_row && start_col <= end_col) {
	for (int i = start_col; i <= end_col ; i++) {
		cout << a[start_row][i] << " ";
	}
	start_row++;

	for (int i = start_row; i <= end_row; i++) {
		cout << a[i][end_col] << " ";
	}
	end_col--;

	for (int i = end_col; i >= start_col; i--) {
		cout << a[end_row][i] << " ";
	}
	end_row--;

	for (int i = end_row; i >= start_row; i--) {
		cout << a[i][start_col] << " ";
	}
	start_col++;
}

}
int main() {
int a[1000][1000] = {0};

int b = 1;
int m, n;
cin >> m >> n;
for (int row = 0; row < m; row++) {
	for (int col = 0; col < n; col++) {
		a[row][col] = b++;


		cout << a[row][col] << " ";
	}
	cout << endl;
}
spiralprint(a, m, n);
return 0;

}

why my code is not working properly ??

Hey share your code using ide.codingblocks.com, if you don’t know how to do that. You can also ask me that too.

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.