Advertisement
wendellcardoso

Programação Modular - Matrizes, Média, Linha

Feb 22nd, 2017
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.83 KB | None | 0 0
  1. #include <iostream>
  2. #include <cstdlib>
  3. #include <locale.h>
  4.  
  5. using namespace std;
  6.  
  7. const int lin=4, col=4;
  8. typedef float tMat[lin][col];
  9.  
  10. void criaMat(tMat &mat)
  11. {
  12.     for(int i=0; i<lin; i++)
  13.         for(int j=0; j<col; j++)
  14.         {
  15.             cout<<"Informe um número: ";
  16.             cin>>mat[i][j];
  17.         }
  18. }
  19.  
  20. void mostraMat(tMat mat)
  21. {
  22.     cout<<endl;
  23.     for(int i=0; i<lin; i++)
  24.     {
  25.         for(int j=0; j<col; j++)
  26.             cout<<mat[i][j]<<" ";
  27.        
  28.         cout<<endl;
  29.     }
  30. }
  31.  
  32. float medPriLin(tMat mat)
  33. {
  34.     int i=0, soma=0;
  35.     float media;
  36.    
  37.     for(int j=0; j<col; j++)
  38.         soma+=mat[i][j];
  39.    
  40.     media=soma/col;
  41.    
  42.     return media;
  43. }
  44.  
  45. int main()
  46. {
  47.     setlocale(LC_ALL, "Portuguese");
  48.    
  49.     tMat mat;
  50.     float result_media;
  51.    
  52.     criaMat(mat);
  53.     mostraMat(mat);
  54.     result_media=medPriLin(mat);
  55.    
  56.     cout<<"\nMédia dos elementos da 1ª linha: "<<result_media;
  57.    
  58.     return 0;
  59. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement