Take as input a 2-d array.Print the 2-D array in sprial form clockwise. What is the error in the following code

using namespace std;
void spiralPrint(int a[][10],int n,int m){
// initialization of the 4 iterators;

int sr=0,sc=0;
int er=n-1,ec=m-1; 

// condition till the loop works;
while(sc<=ec && sr<=er){// till they over shoot each other

    // step 1 to print first row;
    //print the sr from sc to ec
    for (int col=sc;col<=ec;col++){
        cout<<a[sr][col]<<", ";

    // step 2 to print the last column
    // print ec from sr to er;
    // ec--;
    for (int row=sr;row<=er;row++){
        cout<<a[row][ec] <<", ";

    // step 3 to print the last row;
    // print er from ec to sc;
    // er--
    for(int col=ec;col>=sc;col--){
        cout<<a[er][col]<<", ";

    // step 4 to print first row reverse;
    // print sc from er to sr;
    // sc++;
    for(int row=er;row>=sr;row--){
        cout<<a[row][sc]<<", ";

int main(){
int m,n;
int a[10][10];
for(int i=0;i<n;i++){
for(int j=0;j<m;j++){

return 0;


hi @nitinchauhan0808_be04315530401452 updated https://ide.codingblocks.com/s/664213

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.