#include <bits/stdc++.h>
using namespace std;
#define R 3
#define C 6
int PrintSpiral(int arr[][C], int m, int n){
int t= 0, b = m-1, l = 0, r = n-1;
int dir = 0;`
while(l <= r && t <= b){
if(dir == 0){
for(int k = l; k <= r; k++)
cout << arr[t][k];
t++;
}
else if(dir == 1){
for(int k = t; k <= b; k++)
cout << arr[k][r];
r--;
}
else if(dir == 2){
for(int k = r; k >= l; k--)
cout << arr[b][k];
b--;
}
else if(dir == 3){
for(int k = b; k >= t; k--)
cout << arr[k][l];
l++;
}
dir = (dir+1)%4;
}
}
int main() {
//code
int t;
cin>>t;
while(t--){
int na,ma;
cin>>na>>ma;
int ar[na][ma] = {{0}};
for(int i = 0; i < na; i++){
for(int j = 0; j < ma; j++){
cin>>ar[i][j];
}
}
PrintSpiral(ar,na,ma);
}
return 0;
}
I am getting this error:
Spiral_matrix.cpp: In function 'int main()':<br/>
Spiral_matrix.cpp:47:18: error: cannot convert 'int (*)[ma]' to 'int (*)[6]'
PrintSpiral(ar,na,ma);
^~
Spiral_matrix.cpp:6:21: note: initializing argument 1 of 'int PrintSpiral(int (*)[6], int, int)'
int PrintSpiral(int arr[][C], int m, int n){
Error Resolving the issue. Kindly look into it
The above code prints the given 2-D matrix into
Spiral form
I applied arr[][6]
with random value and also i predefined column as C
and updated it again with arr[][C]
still it shows an error
Apart from this i even used the value of R and C in my main function
Still it shows an error
I want a way in which i could pass my function successfully in the main function.