Advertisement
luizaspan

Multiplicação matriz vetor

Jun 9th, 2015
470
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.67 KB | None | 0 0
  1. // sobre matrizes: arrays de dimensão 2
  2.  
  3. // fazer código para produto A[10][4]*x[10]. Inicializar primeiramente todos os elementos =1.
  4.  
  5. #include <stdio.h>
  6.  
  7. int main(void)
  8. {
  9.     int A[10][4],y[4]; // matriz: 10 linhas, 4 colunas
  10.     int i,j,k;
  11.  
  12.     int x[]={1,2,3,4,5,6,7,8,9,10}; // 10 elementos
  13.  
  14.     for(i=0;i<10;i++) // definir elementos da matriz
  15.     {
  16.         for(j=0;j<4;j++)
  17.         {
  18.             A[i][j]=1;
  19.             // printf("A[%d][%d]=%d\n",i,j,A[i][j]);
  20.         }
  21.     }
  22.  
  23.     // A[2][2]=4;
  24.  
  25.     for(j=0;j<4;j++) // fazendo a multiplicação do vetor pela matriz
  26.     {
  27.         y[j]=0;
  28.  
  29.         for(i=0;i<10;i++)
  30.         {
  31.             y[j]+=A[i][j]*x[i];        
  32.         }
  33.     }
  34.  
  35.     for(k=0;k<4;k++)
  36.         printf("y[%d]=%d \n",k,y[k]);
  37.  
  38.     return 0;
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement