Advertisement
Guest User

Untitled

a guest
May 4th, 2014
309
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.88 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3. #include <string>
  4. using namespace std;
  5. //---------------------------------------------
  6. const string CDfv = "Duomenys.txt";
  7. const int CMax = 500;
  8. //---------------------------------------------
  9. void Skaityti(double A[], int & n);
  10. double Vidurkis(double A[], int n);
  11. //---------------------------------------------
  12. int main()
  13. {
  14.     double A[CMax];
  15.     int n;
  16.     Skaityti(A, n);
  17.     cout << Vidurkis(A, n) << endl;
  18.     return 0;
  19. }
  20. //---------------------------------------------
  21. void Skaityti(double A[], int & n)
  22. {
  23.     double ugis;
  24.     ifstream fd(CDfv);
  25.     fd >> n;
  26.     for(int i = 0; i < n; i++)
  27.     {
  28.         fd >> ugis;
  29.     if(ugis < 0)
  30.         A[i] = ugis * (-1);
  31.     else
  32.         A[i] = ugis;
  33.     }
  34. }
  35. //---------------------------------------------
  36. double Vidurkis(double A[], int n)
  37. {
  38.     double suma = 0;
  39.     for(int i = 0; i < n; i++)
  40.         suma = suma + A[i];
  41.     return suma / n;
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement