WiktoriaRatajczyk

Zadanie10

Apr 16th, 2020
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.77 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. float srednia (int n, int *tab)
  6. {
  7.     int l=n;
  8.     float sr=0;
  9.     while(n--)
  10.         sr+=*tab++;
  11.     return (sr/l);
  12. }
  13.  
  14. void wypelnij(int tab[4][5])
  15. {
  16.     for (int i=0; i<4; ++i)
  17.     {
  18.         for(int j=0;j<5;++j)
  19.         {
  20.             cout<<"Wpisz ocene uczniowi "<<i<<": ";
  21.             cin>>tab[i][j];
  22.         }
  23.     }
  24. }
  25.  
  26. int sred(int tab[4][5])
  27. {
  28.     float sred=0;
  29.     int isred;
  30.     for(int i=0;i<4;++i){
  31.         float s=srednia(5,tab[i]);
  32.         if(s>sred){
  33.         sred=s;
  34.         isred=i;
  35.         }
  36.     }
  37.  
  38.     cout<<"Najwieksza srednia ma uczen "<<isred<<". Wynosi ona: "<<sred<<endl;
  39.     return sred;
  40. }
  41.  
  42. int main()
  43. {
  44.     int tab[4][5];
  45.     wypelnij(tab);
  46.     sred(tab);
  47.     return 0;
  48. }
Add Comment
Please, Sign In to add comment