Welcome!

By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!
  • Guest, before posting your code please take these rules into consideration:
    • It is required to use our BBCode feature to display your code. While within the editor click < / > or >_ and place your code within the BB Code prompt. This helps others with finding a solution by making it easier to read and easier to copy.
    • You can also use markdown to share your code. When using markdown your code will be automatically converted to BBCode. For help with markdown check out the markdown guide.
    • Don't share a wall of code. All we want is the problem area, the code related to your issue.


    To learn more about how to use our BBCode feature, please click here.

    Thank you, Code Forum.

C++ What's wrong with this spiral matrix code?

#include<bits/stdc++.h>
using namespace std;
void spiralprint(int arr[10000][10000],int m, int n){
int startrow=0;
int startcol=0;
int endrow=m-1;
int endcol=n-1;
while(startrow<=endrow && startcol<=endcol){
for(int i=startcol;i<=endcol;i++){
cout<<arr[startrow]<<" ";
}
startrow++;
for(int i=startrow;i<=endrow;i++){
cout<<arr[endcol]<<" ";
}
endcol--;
if(endrow>startrow){
for(int i=endcol;i>=startcol;i--){
cout<<arr[endcol]<<" ";
}
endrow--;
}
if(endcol>startcol){
for(int i=endrow;i>=startrow;i--){
cout<<arr[startcol]<<" ";
}
startcol++;
}
}
}
int main()
{
int arr[10000][10000];
int i,m,n,j;
cin>>m>>n;
for(i=0;i<m;i++){
for(j=0;j<n;j++){
cin>>arr[j];
}
}
spiralprint(arr,m,n);
}
 
You haven't said what your problem is.

And also, please put your code in the "Code" feature. The button should look like this: </>
 
Last edited:
As Johna said, you should always clearly state what problems you are facing. But I can see three things wrong to start with.

1 - This code does not compile because <bits/stdc++.h> does not exist. At least not in my Visual Studio 2022 environment.

2 - This code does not compile because you use cin and cout but do not have #include <iostream>.

3 - This code does does not compile because the compiler can't handle the statement cin >> arr[j]; The variable arr[j] is an array of 10000 int's, and there is no built-in C++ code to convert user input to an array - even if you typed in all your 10000 values, which you probably not intended to do.

Of course there may be more wrong with the code, once you get it to compile...
 
Last edited by a moderator:

New Threads

Latest posts

Buy us a coffee!

Back
Top Bottom