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

“Complete o seguinte programa:
(…)
A função escreve() deve mostrar o conteúdo de uma matriz de inteiros na consola. A função recebe como argumentos o número de linhas, o número de colunas e o endereço inicial da matriz. Neste exemplo, o resultado será o seguinte:

#include <stdio.h>
#define L1 3
#define C1 2
#define L2 4
#define C2 3

void escreve(int n_lin, int n_col, int *m)
{
  int *p, i=0, j=0;
  p=m;
  for(i=0; i<n_lin; i++){
      for(j=0; j<n_col; j++, p++){
          printf("%d\t", *p);
  }
  printf("\n");
}
}

int main()
{
 int mat1[L1][C1]={{1,2},{3,4},{5,6}};
 int mat2[L2][C2]={{1,2,3},{4,5,6},{7,8,9},{10,11,12}};

 printf("\nMatriz mat1:\n");
 escreve(L1, C1, mat1);
 printf("\nMatriz mat2:\n");
 escreve(L2, C2, mat2);
 return 0;
}


Tags :

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

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.