Advertisement
Leticia22

Transpuesta

Mar 27th, 2017
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.81 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #define N 3
  4.  
  5. /*
  6.  *
  7.  */
  8. void transp(int M[N][N],int n){
  9.     int i;
  10.     int aux;
  11.     if(n==1)
  12.         return;
  13.    
  14.     else{
  15.         for(i=0;i<n;i++){
  16.             aux=M[n-1][i];
  17.             M[n-1][i]=M[i][n-1];
  18.             M[i][n-1]=aux;            
  19.         }
  20.         transp(M,n-1);
  21.    
  22.     }    
  23.    
  24. }
  25.  
  26. void impMat(int M[N][N],int n){
  27.     int i,j;
  28.     for(i=0;i<n;i++){
  29.         for(j=0;j<n;j++){
  30.             printf("%d ",M[i][j]);
  31.         }
  32.         printf("\n");
  33.     }
  34. }
  35.  
  36. int main(int argc, char** argv) {
  37.     //int M[N][N]={ {1, 2}, {3, 4}};
  38.     int M[N][N]={ {3, 5, 7}, {1, 3, 4}, {8, 3, 1}};
  39.    
  40.     int n=3;
  41.    
  42.    
  43.     impMat(M,n);
  44.     transp(M,n);
  45.     printf("Resultado:\n");
  46.     impMat(M,n);
  47.    
  48.  
  49.     return (EXIT_SUCCESS);
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement