Informática, perguntado por photinoco, 9 meses atrás

Leia duas matrizes 4 x 4 e escreva uma terceira com os maiores valores de cada posição
das matrizes lidas. C++

Soluções para a tarefa

Respondido por franklinnascimentolo
4

Resposta:

#include <stdio.h>

int main(void)

{

int A[4][4], B[4][4], C[4][4];

/** le a matriz A */

for(int i = 0; i < 4; i++)

{

 for(int j = 0; j < 4; j++)

 {

  printf("A(%i,%i) = ", i, j);

  scanf("%i", &A[i][j]);

 }

}

/** le a matriz B */

for(int i = 0; i < 4; i++)

{

 for(int j = 0; j < 4; j++)

 {

  printf("B(%i,%i) = ", i, j);

  scanf("%i", &B[i][j]);

 }

}

/* compara as matrizes A e B

   e preenche a matriz C com o maior */

for(int i = 0; i < 4; i++)

{

 for(int j = 0; j < 4; j++)

 {

  if(A[i][j] >= B[i][j])

  {

   C[i][j] = A[i][j];

  }

  else

  {

   C[i][j] = B[i][j];

  }

 }

}

for(int i = 0; i < 4; i++)

{

 for(int j = 0; j < 4; j++)

 {

  printf("C(%i,%i) = %i\n", i, j, C[i][j]);

 }

}

return 0;

}

Perguntas interessantes