Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- int m, n, i, j;
- int **mat;
- int **res;
- void printMat(int **res, int i, int j, int righe, int colonne){
- for(i=0;i<righe;i++){
- printf("\n");
- for(j=0;j<colonne;j++){
- printf("%d ", res[i][j]);
- }
- }
- printf("\n\n\n\n");
- }
- int ** trasposta(int **mat, int j, int i, int n, int m, int **res){
- printf("ci sono\n");
- res=(int **)malloc(m*sizeof(int *));
- for(i=0;i<n;i++){
- res[i]=(int *)malloc(n*sizeof(int));
- if(res[i]==NULL) exit(EXIT_FAILURE);
- }
- printf("ci sono\n");
- printMat(res,i,j,m,n);
- for(i=0;i<n;i++){
- for(j=0;j<m;j++){
- res[j][i]=mat[i][j];
- }
- }
- printf("ci sono\n");
- return res;
- }
- int main(){
- printf("inserisci n. righe: ");
- scanf("%d", &n);
- printf("inserisci n. colonne ");
- scanf("%d", &m);
- printf("porcodio\n");
- mat=(int **)malloc(n*sizeof(int *));
- for(i=0;i<m;i++){
- mat[i]=(int *)malloc(m*sizeof(int));
- if(mat[i]==NULL){
- exit(EXIT_FAILURE);
- }
- }
- printf("diocane\n");
- for(i=0;i<n;i++){
- for(j=0;j<m;j++){
- mat[i][j]=rand();
- }
- }
- printf("edddai su\n");
- printMat(mat,i,j,n,m);
- res=trasposta(mat,j,i,n,m,res);
- printMat(res,i,j,m,n);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement