Advertisement
adas291

matasdx

Jan 13th, 2020
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.35 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3. #include <iomanip>
  4.  
  5. using namespace std;
  6.  
  7. const char FV[] = "data.txt";
  8. const char FD[] = "output.txt";
  9.  
  10. int a[7];
  11. int b[7];
  12.  
  13. double Vidurkis(int u[], int n);
  14. void Atmetimas(int u[], int &n);
  15. void Suvedimas(const char FV[], int a[], int b[], int n);
  16.  
  17. int main()
  18. {
  19.     ifstream in(FV);
  20.     ofstream out(FD);
  21.     int nA, nB, n;
  22.     in >> n;
  23.     nA = n;
  24.     nB = n;
  25.     Suvedimas(FV, a, b, n);
  26.     Atmetimas(a, nA);
  27.     Atmetimas(b, nB);
  28.     double aVid, bVid;
  29.     aVid = Vidurkis(a, nA);
  30.     bVid = Vidurkis(b, nB);
  31.     out << fixed << setprecision(1) << aVid << endl;
  32.     out << fixed << setprecision(1) << bVid << endl;
  33.  
  34. }
  35. void Atmetimas(int u[], int &n)
  36. {
  37.     int didz = 0;
  38.     int maz = 0;
  39.     for(int i = 0; i < n; i++)
  40.     {
  41.         if(u[i] > u[didz]) didz = i;
  42.         if(u[i] < u[maz]) maz = i;
  43.     }
  44.     u[didz] = u[n - 1];
  45.     n--;
  46.     u[maz] = u[n - 1];
  47.     n--;
  48.     //salinimas//
  49.  
  50. }
  51. void Suvedimas(const char FV[], int a[], int b[], int n)
  52. {
  53.     ifstream in(FV);
  54.     in >> n;
  55.     for(int i = 0; i < n; i++)
  56.     {
  57.         in >> a[i];
  58.         in >> b[i];
  59.     }
  60.     in.close();
  61. }
  62. double Vidurkis(int u[], int n)
  63. {
  64.     double sum;
  65.     sum = 0;
  66.     for(int i = 0; i < n; i++)
  67.     {
  68.         sum += u[i];
  69.     }
  70.     double vid;
  71.     vid = sum / n;
  72.     return vid;
  73.  
  74. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement