Advertisement
darkjessy94

rotaz 90 - vincenzo rosso

Dec 10th, 2017
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.25 KB | None | 0 0
  1. #include <stdlib.h>
  2. #include <stdio.h>
  3.  
  4. int *rotate90(int *, int, int);
  5.  
  6. void main()
  7. {
  8. int A_righe, A_col, i, j, *matrice_A, *matrice_B;
  9.  
  10. A_righe = 3;
  11. A_col = 4;
  12.  
  13. matrice_A = (int*)malloc(A_righe*A_col*sizeof(int));
  14.  
  15. for(i = 0; i < A_righe; i++)
  16. for(j = 0; j < A_col; j++)
  17. *(matrice_A + A_righe*j + i) = i + j;
  18.  
  19.  
  20. printf("Matrice A\n\n");
  21. for(i = 0; i < A_righe; i++)
  22. {
  23. printf("\n");
  24.  
  25. for(j = 0; j < A_col; j++)
  26. printf("%d ", *(matrice_A +A_righe*j + i));
  27. }
  28.  
  29. matrice_B = rotate90(matrice_A, A_righe, A_col);
  30.  
  31. printf("\nMatrice B\n\n");
  32. for(i = 0; i < A_col; i++)
  33. {
  34. printf("\n");
  35.  
  36. for(j = 0; j < A_righe; j++)
  37. printf("%d ", *(matrice_B + A_righe*i + j));
  38. }
  39. }
  40.  
  41. int *rotate90(int *matrice_A, int A_righe, int A_col)
  42. {
  43. int B_righe = A_col, B_col = A_righe, *matrice_B;
  44. int i, j, i_B;
  45.  
  46. matrice_B = (int*)malloc(B_righe*B_col*sizeof(int));
  47.  
  48. for(i = 0; i < A_righe; i++)
  49. {
  50. i_B = B_righe - 1;
  51.  
  52. for(j = 0; j < A_col; j++)
  53. {
  54. *(matrice_B + B_col*i_B + i) = *(matrice_A + A_righe*j + i);
  55. i_B--;
  56. }
  57. }
  58.  
  59. return matrice_B;
  60.  
  61. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement