Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdlib.h>
- #include <stdio.h>
- int *rotate90(int *, int, int);
- void main()
- {
- int A_righe, A_col, i, j, *matrice_A, *matrice_B;
- A_righe = 3;
- A_col = 4;
- matrice_A = (int*)malloc(A_righe*A_col*sizeof(int));
- for(i = 0; i < A_righe; i++)
- for(j = 0; j < A_col; j++)
- *(matrice_A + A_righe*j + i) = i + j;
- printf("Matrice A\n\n");
- for(i = 0; i < A_righe; i++)
- {
- printf("\n");
- for(j = 0; j < A_col; j++)
- printf("%d ", *(matrice_A +A_righe*j + i));
- }
- matrice_B = rotate90(matrice_A, A_righe, A_col);
- printf("\nMatrice B\n\n");
- for(i = 0; i < A_col; i++)
- {
- printf("\n");
- for(j = 0; j < A_righe; j++)
- printf("%d ", *(matrice_B + A_righe*i + j));
- }
- }
- int *rotate90(int *matrice_A, int A_righe, int A_col)
- {
- int B_righe = A_col, B_col = A_righe, *matrice_B;
- int i, j, i_B;
- matrice_B = (int*)malloc(B_righe*B_col*sizeof(int));
- for(i = 0; i < A_righe; i++)
- {
- i_B = B_righe - 1;
- for(j = 0; j < A_col; j++)
- {
- *(matrice_B + B_col*i_B + i) = *(matrice_A + A_righe*j + i);
- i_B--;
- }
- }
- return matrice_B;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement