Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- /// m x n
- #define max 4
- void rotate(int* A,int m,int n);
- int main()
- {
- int n=3,m=3,i,j,c=0;
- int *A;
- A=(int*)calloc(1,m*n*sizeof(int));
- for (i=0;i<m;i++)
- {
- for(j=0;j<n;j++)
- {
- *(A+j*m+i)=++c;
- }
- }
- for (i=0;i<m;i++)
- {
- printf("\n");
- for(j=0;j<n;j++)
- {
- printf("\t%d ",*(A+i*n+j));
- }
- }
- rotate(A,m,n);
- return 0;
- }
- void rotate(int *A,int m,int n)
- {
- int i,j,ib=n-1,jb=0,*B;
- B=(int*)calloc(1,m*n*sizeof(int));
- for(i=0; i<m; i++)
- {
- for(j=0;j<n;j++)
- {
- *(B+ib*n+jb)=*(A+j*m+i);///
- jb++;
- }
- ib--;
- jb=0;
- }
- printf("\n\n\n");
- for(i=0;i<m;i++)
- {
- printf("\n");
- for(j=0;j<n;j++)
- {
- printf("\t%d",*(B+i*n+j));
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement