+ 2
Wrong results is shown by the compiler is their error in my logic or something else
Written one program in c to rotate a matrix https://code.sololearn.com/csG6raJx4oOG/?ref=app
6 Réponses
+ 3
Got the error which is general for 3 ×3 matrix
+ 3
Really? Because I don't. Check again. Change your last two loops to
for (i=0;i<n;i++){
for(j=0;j<m;j++){
...
}
}
Your first and second loop is
for (i=0;i<m;i++){
for(j=0;j<n;j++){
...
}
}
Note that I swap the m and n
And change your third loop to
b[ i ][ j ] = a[ j ][ n - 1 - i ]
Note the changes
+ 2
Got the error
+ 2
Yes
+ 1
Try changing your last two loops to
for (i=0;i<n;i++){
for(j=0;j<m;j++){
b[i][j]=a[j][n - 1 - i];
}
} printf ("\nRotated matrix is\n");
for (i=0;i<n;i++){
for(j=0;j<m;j++){
printf("%d",b[i][j]);
}
+ 1
If you still got an error, show me the code then