#include
using namespace std;
int R = 0, C = 0;
void counterClockspiralPrint(int m, int n, int arr[R][C])
{
int i, k = 0, l = 0;
int cnt = 0;
int total = m * n;
while (k < m && l < n)
{
if (cnt == total)
break;
for (i = k; i < m; ++i)
{
cout << arr[i][l] << " ";
cnt++;
}
l++;
if (cnt == total)
break;
for (i = l; i < n; ++i)
{
cout << arr[m - 1][i] << " ";
cnt++;
}
m--;
if (cnt == total)
break;
if (k < m)
{
for (i = m - 1; i >= k; --i)
{
cout << arr[i][n - 1] << " ";
cnt++;
}
n--;
}
if (cnt == total)
break;
// Print the first row
// from the remaining rows
if (l < n)
{
for (i = n - 1; i >= l; --i)
{
cout << arr[k][i] << ", ";
cnt++;
}
k++;
}
}
cout<<"END"<<endl;
}
int main() {
int m, n;
cin>>m>>n;
int a[m][n];
R = m;
C = n;
for(int i = 0; i < m; i++)
{
for(int j = 0; j < n; j++)
{
cin>>a[i][j];
}
}
counterClockspiralPrint(m, n, a);
return 0;
}
although my error arr is declared in the function and R and C are global variable than also I am getting error with this two thing which I am unable to sort out , please suggest something suitable