Once correct my code

plz correct my code sir what is the mistake

hi @tarun1010
u haven’t shared ur code… refer this -->

#include using namespace std; void Spiral(int arr[][100],int n,int m) { int sr=0; int sc=0; int er=n-1; int ec=m-1; //print sr from sc->ec for(int col=sc;col<=ec;col++) { cout<<arr[sr][col]<<","; } sr++; //2 for(int row=sr;row<=er;row++) { cout<<arr[row][ec]<<","; } ec–; //3 er if(sr<=er) { for(int col=ec;col>=sc;col–) { cout<<arr[er][col]<<","; } er–; } //4 if(sc<=ec) { for(int row=er;row>=sr;row–) { cout<<arr[row][sc]<<","; } sc++; } cout<<endl; } int main() { int n,m; cin>>n; cin>>m; int arr[100][100]; for(int row=0;row<n;row++) { for(int col=0;col<m;col++) { cin>>arr[row][col]; } } Spiral(arr,n,m); }

kindly save it on coding blocks ide and send link… like this its not in readable format…

i have send the code

#include

using namespace std;

void Spiral(int arr[][100],int n,int m)

{

int sr=0;

int sc=0;

int er=n-1;

int ec=m-1;

//print sr from sc->ec

for(int col=sc;col<=ec;col++)

{

    cout<<arr[sr][col]<<",";

}

sr++;

//2

for(int row=sr;row<=er;row++)

{

    cout<<arr[row][ec]<<",";

}

ec--;

//3 er

 if(sr<=er)

{

    for(int col=ec;col>=sc;col--)

    {

        cout<<arr[er][col]<<",";

    }

    er--;

}

//4

if(sc<=ec)

{

  for(int row=er;row>=sr;row--)

   {

       cout<<arr[row][sc]<<",";

   }



sc++;

}

cout<<endl;

}

int main() {

int n,m;

cin>>n;

cin>>m;

int arr[100][100];

for(int row=0;row<n;row++)

{

    for(int col=0;col<m;col++)

    {

        cin>>arr[row][col];

    }

}

Spiral(arr,n,m);

}

bhaiay i have sent the code

@tarun1010
there were 3 error…

  1. while(sr <= er && sc <= ec){ u haven’t consider this loop… as a result only boundary elements were getting printed…
  2. while printing elements after comma, give a space…
  3. u have to write END after printing all the elements

corrected code -->


It’s working fine and passing all test cases…

@tarun1010
I hope its clear now??

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.