Advertisement
F_THIAGO

Matrizes - Questão 2

Feb 13th, 2019
325
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.76 KB | None | 0 0
  1. #include <stdio.h>
  2.  
  3. /*
  4. *  Criar um algoritmo que leia os elementos de uma matriz inteira
  5. * de 3x3 e imprimir outra matriz multiplicando cada elemento da
  6. * primeira matriz por 2.
  7. */
  8.  
  9. int main( void )
  10. {
  11.     // Cria as variaveis usadas
  12.     int matriz[3][3];
  13.     int linhas, colunas;
  14.    
  15.     // Preenche a matriz pelo teclado
  16.     for( linhas=0; linhas<3; linhas++ )
  17.     {
  18.         for( colunas=0; colunas<3; colunas++ )
  19.         {
  20.             printf("Elemento [%d][%d]: ", linhas, colunas);
  21.             scanf("%d", &matriz[linhas][colunas]);
  22.         }
  23.     }
  24.    
  25.     // Exibe a matriz
  26.     printf("\n");
  27.     for( linhas=0; linhas<3; linhas++ )
  28.     {
  29.         for( colunas=0; colunas<3; colunas++ )
  30.              printf("%d ", matriz[linhas][colunas] * 2); // Exibe o elemento da matriz multiplicada por 2
  31.              
  32.         printf("\n");
  33.     }
  34.    
  35.     return 0;
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement