Guião laboratorial n.º 1 – exercício 17

“Desenvolva uma função que efetue a transposição numa matriz N*N de inteiros. A transposição consiste em trocar as linhas pelas colunas. A função recebe como argumentos o endereço inicial da matriz e o valor N (pode assumir que a matriz é quadrada).”

#include <stdio.h>
#define L1 3
#define C1 3

void transpor_q(int l, int c, int *m1)
{
  int *p, *q, aux[l][c],aux2[l][c],i,j;
  p=m1;
  q=m1;

  for(i=0; i<l; i++){
      for(j=0; j<c; j++, p++){
          aux[j][i]=*p;
          printf("%d\t", aux[j][i]);
          q=p;
      }
  printf("\n");
  }

  for(i=0; i<l; i++){
      for(j=0; j<c; j++){
          *p=aux[i][j];
          printf("%d\t", *p);
      }
  printf("\n");
  }
}

int main()
{
 int matA[L1][C1]={{1,2,3},{4,5,6},{7,8,9}};

 printf("\nMatriz da soma:\n");
 transpor_q(L1, C1, matA);
 return 0;
}



Tags :

0 thoughts on “Guião laboratorial n.º 1 – exercício 17”

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.