+ 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

30th Jun 2019, 8:54 AM
Sharma Abhishek
 Sharma Abhishek  - avatar
6 odpowiedzi
+ 3
Got the error which is general for 3 ×3 matrix
1st Jul 2019, 10:13 AM
Sharma Abhishek
 Sharma Abhishek  - avatar
+ 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
30th Jun 2019, 10:42 AM
Agent_I
Agent_I - avatar
+ 2
Got the error
30th Jun 2019, 10:31 AM
Sharma Abhishek
 Sharma Abhishek  - avatar
+ 2
Yes
30th Jun 2019, 10:44 AM
Sharma Abhishek
 Sharma Abhishek  - avatar
+ 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]); }
30th Jun 2019, 10:26 AM
Agent_I
Agent_I - avatar
+ 1
If you still got an error, show me the code then
30th Jun 2019, 10:46 AM
Agent_I
Agent_I - avatar