Advertisement
Guest User

filoaiuto

a guest
Jan 26th, 2020
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.21 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. int m, n, i, j;
  5. int **mat;
  6. int **res;
  7.  
  8.  
  9.  
  10.  
  11. void printMat(int **res, int i, int j, int righe, int colonne){
  12. for(i=0;i<righe;i++){
  13. printf("\n");
  14. for(j=0;j<colonne;j++){
  15. printf("%d ", res[i][j]);
  16. }
  17. }
  18. printf("\n\n\n\n");
  19. }
  20.  
  21.  
  22.  
  23.  
  24.  
  25. int ** trasposta(int **mat, int j, int i, int n, int m, int **res){
  26. printf("ci sono\n");
  27. res=(int **)malloc(m*sizeof(int *));
  28. for(i=0;i<n;i++){
  29. res[i]=(int *)malloc(n*sizeof(int));
  30. if(res[i]==NULL) exit(EXIT_FAILURE);
  31. }
  32.  
  33. printf("ci sono\n");
  34. printMat(res,i,j,m,n);
  35.  
  36. for(i=0;i<n;i++){
  37. for(j=0;j<m;j++){
  38. res[j][i]=mat[i][j];
  39. }
  40. }
  41. printf("ci sono\n");
  42.  
  43. return res;
  44. }
  45.  
  46.  
  47.  
  48. int main(){
  49. printf("inserisci n. righe: ");
  50. scanf("%d", &n);
  51. printf("inserisci n. colonne ");
  52. scanf("%d", &m);
  53. printf("porcodio\n");
  54. mat=(int **)malloc(n*sizeof(int *));
  55. for(i=0;i<m;i++){
  56. mat[i]=(int *)malloc(m*sizeof(int));
  57. if(mat[i]==NULL){
  58. exit(EXIT_FAILURE);
  59. }
  60. }
  61. printf("diocane\n");
  62.  
  63. for(i=0;i<n;i++){
  64. for(j=0;j<m;j++){
  65. mat[i][j]=rand();
  66. }
  67. }
  68. printf("edddai su\n");
  69.  
  70. printMat(mat,i,j,n,m);
  71.  
  72. res=trasposta(mat,j,i,n,m,res);
  73.  
  74. printMat(res,i,j,m,n);
  75.  
  76. return 0;
  77.  
  78. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement