#include
using namespace std;
// Spiral print anticlokwise
void spiralPrint( int m, int n, int a[][n]) {
int k=0, l=0;
// m–> rows, n–>columns
while(k < m && l <n) {
// first complete columns
for(int i=k; i<m; i++) {
cout << a[i][l] << ", ";
}
l++;
// last complete row with one index
for(int i=l; i<n; i++) {
cout << a[m-1][i] << ", ";
}
m--;
if(k<m){
for(int i=m-1; i>=k; i--){
cout << a[i][n-1] << ", ";
}
n--;
}
if(l<n) {
for(int i=n-1; i>=l; i--) {
cout << a[k][i] << ", ";
}
k++;
}
}
cout << "END";
}
int main() {
int m,n;
cin >> m >> n;
if(m < 11 && n < 11){
int a[m][n];
for(int i=0; i<m; i++) {
for(int j=0; j<n; j++) {
cin >> a[i][j];
}
}
spiralPrint(m,n,a);
}
return 0;
}
Compiling failed with exitcode 1, compiler output:
prog.cpp:5:42: error: use of parameter outside function body before ‘]’ token
void spiralPrint( int m, int n, int a[][n]) {
^
prog.cpp: In function ‘void spiralPrint(…)’:
prog.cpp:8:15: error: ‘m’ was not declared in this scope
while(k < m && l <n) {
^
prog.cpp:8:23: error: ‘n’ was not declared in this scope
while(k < m && l <n) {
^
prog.cpp:11:21: error: ‘a’ was not declared in this scope
cout << a[i][l] << ", ";
^
prog.cpp:17:21: error: ‘a’ was not declared in this scope
cout << a[m-1][i] << ", ";
^
prog.cpp:22:25: error: ‘a’ was not declared in this scope
cout << a[i][n-1] << ", ";
I am getting the arrays like above not able to pass the array to function