diogoAlves

IFF/Introdução à Programação/Slide/Pag 48/Ex 5

Mar 7th, 2018
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.95 KB | None | 0 0
  1. //IFF - Introdução à Programação
  2. //Slide - Página 48 - Exercício 5
  3. #include<stdio.h>
  4. #include<locale.h>
  5.  
  6. int main(){
  7.     setlocale(LC_ALL,"Portuguese");
  8.     int check=0;
  9.     float aux=0,matriz1[3][2],matriz2[3][2],matriz[2][3],matriz3[3][3]={0};
  10.     for(int l=0,c=0;l<3;l++){
  11.         for(c=0;c<2;c++){
  12.             printf("Entre com o valor da posição (%d,%d): ",l+1,c+1);
  13.             if(check==0) scanf("%f",&matriz1[l][c]); else scanf("%f",&matriz2[l][c]);
  14.         }
  15.         if((l==2)&&(check==0)){
  16.             check=1;
  17.             l=-1;
  18.             c=0;
  19.         }
  20.     }
  21.     for(int l=0;l<2;l++){
  22.         for(int c=0;c<3;c++){
  23.             matriz[l][c]=matriz2[c][l];
  24.         }
  25.     }
  26.     for(int l=0;l<3;l++){
  27.         for(int c=0;c<3;c++){
  28.             matriz3[l][c]=0;
  29.             for(int k=0; k<2;k++){
  30.                 matriz3[l][c]+=matriz1[l][k]*matriz[k][c];
  31.             }  
  32.         }
  33.     }
  34.     printf("\n\nA matriz 3, resultado da multiplicação das matrizes entradas anteriormente: \n");
  35.     for(int l=0;l<3;l++){
  36.         for(int c=0;c<3;c++){
  37.             printf("%.0f ",matriz3[l][c]);
  38.         }
  39.         printf("\n");
  40.     }
  41. }
Advertisement
Add Comment
Please, Sign In to add comment