below mentioned code is working well in online ide but not in my local machine while other codes are working well.
#include
using namespace std;
void spiral_print(int arr[][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)
{
//First row
for (int col = start_col; col <= end_col; col++)
{
cout << arr[start_row][col] << " ";
}
start_row++;
//End Column
for (int row = start_row; row <= end_row; row++)
{
cout << arr[row][end_col] << " ";
}
end_col--;
//End row
for (int col = end_col; col >= start_col; col--)
{
cout << arr[end_row][col] << " ";
}
end_row--;
//Start Column
for (int row = end_row; row >= start_row; row--)
{
cout << arr[row][start_col] << " ";
}
start_col++;
}
}
int main()
{
#ifndef ONLINE_JUDGE
freopen(“input.txt”, “r”, stdin);
freopen(“output.txt”, “w”, stdout);
#endif
int m, n;
cin >> m >> n;
int arr[1000][1000];
int val = 1;
for (int row = 0; row < m; row++)
{
for (int col = 0; col < n; col++)
{
arr[row][col] = val;
val++;
}
}
spiral_print(arr, m, n);
return 0;
}