What is error in this code?

#include
using namespace std;

void rotate(int a[][1000], int n){
for (int row=0; row<n; row++){
int startcol=0;
int endcol=n;
while(startcol<endcol){
swap(a[row][startcol],a[row][endcol]);
startcol++;
endcol–;
}
}
for (int i=0; i<n; i++){
for(int j=0; j<n; j++){
if(i<j){
swap(a[i][j],a[j][i]);
}
}
}
}

int main() {
int n;
int a[1000][1000];
cin>>n;
for (int i=0; i<n; i++){
for(int j=0; j<n; j++){
cin>>a[i][j];
}
}
rotate(a,n);
for (int i=0; i<n; i++){
for(int j=0; j<n; j++){
cout<<a[i][j]<<" ";
}
cout<<endl;
}

return 0;

}

what is the error in my code?

@itismohiton
hello mohit,
first u need to take transpone and then reverse each row.

you are doing opposite

it is showing compilation error. And i used the same concept as taught in video lecture.

and this code is same as of video lecture.

here endcol should be n-1

1 Like

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.