Advertisement
darkjessy94

mat90rotate

Oct 2nd, 2017
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.00 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. /// m x n
  4. #define max 4
  5.  
  6. void rotate(int* A,int m,int n);
  7. int main()
  8. {
  9.     int n=3,m=3,i,j,c=0;
  10.     int *A;
  11.     A=(int*)calloc(1,m*n*sizeof(int));
  12.  
  13.     for (i=0;i<m;i++)
  14.     {
  15.         for(j=0;j<n;j++)
  16.         {
  17.             *(A+j*m+i)=++c;
  18.         }
  19.     }
  20.     for (i=0;i<m;i++)
  21.     {
  22.         printf("\n");
  23.         for(j=0;j<n;j++)
  24.         {
  25.             printf("\t%d ",*(A+i*n+j));
  26.         }
  27.     }
  28.  
  29.     rotate(A,m,n);
  30.     return 0;
  31. }
  32.  
  33. void rotate(int *A,int m,int n)
  34. {
  35.     int i,j,ib=n-1,jb=0,*B;
  36.  
  37.     B=(int*)calloc(1,m*n*sizeof(int));
  38.  
  39.     for(i=0; i<m; i++)
  40.         {
  41.             for(j=0;j<n;j++)
  42.                 {
  43.                     *(B+ib*n+jb)=*(A+j*m+i);///
  44.                     jb++;
  45.                 }
  46.             ib--;
  47.             jb=0;
  48.         }
  49.  
  50. printf("\n\n\n");
  51.    for(i=0;i<m;i++)
  52.     {
  53.         printf("\n");
  54.         for(j=0;j<n;j++)
  55.             {
  56.                 printf("\t%d",*(B+i*n+j));
  57.             }
  58.     }
  59. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement