Regarding spiral print

#include<bits/stdc++.h>
using namespace std;
int main()
{
int a[10][10];
int ro,c;
cin>>ro>>c;
for(int i=0;i<ro;i++)
{

    for(int j=0;j<c;j++)
    {
        cin>>a[i][j];
    }
}
for(int i=0;i<ro;i++)
{
    for(int j=0;j<c;j++)
    {
        cout<<a[i][j]<<" ";
    }
    cout<<endl;
}
int l=0,b=ro-1,t=0,r=c-1;

while(t<=b && l<=r)
{

    for(int i=l;i<=r;i++)
    {
        cout<<a[t][i]<<" ";

    }
    t++;
    for( int j=t;j<=b;j++)
    {
        cout<<a[j][r]<<" ";

    }

    r--;
    if(b>t)
    {


    for( int i=r;i>=l;i--)
    {
        cout<<a[b][i]<<" ";

    }
    b--;
    }
    if(r>l)
    {


    for( int j=b;j<=t;j--)
    {

        cout<<a[j][l]<<" ";

    }
    l++;
    }

}
cout<<"END";

}
the code is showing run error.Please explain why?

Hello @kushagrathebest,

Please, share your code using online Coding Blocks IDE from next time.
The way you have shared it, is introducing many syntax error.

Steps:

  1. Paste your code on IDE
  2. Save your code there
  3. Share the URL generated.

Now, coming back to your problem:
There are multiple issues with your code:

  1. You have to print the matrix anticlockwise.
    In your code you are doing it clockwise.
    CORRECT THIS

  2. The output format of your code is wrong.
    “,” after each element of matrix is missing.

  3. You are not required to print the array in the output.

Now, for once considering if you were writing code for clockwise spiral print:
Ques:
https://hack.codingblocks.com/contests/c/720/220

Modified Code:

Now, modify the your for the anticlockwise pattern.

Hope, this would help.
Give a like, if you are satisfied.

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.