Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- #include <string>
- using namespace std;
- //---------------------------------------------
- const string CDfv = "Duomenys.txt";
- const int CMax = 500;
- //---------------------------------------------
- void Skaityti(double A[], int & n);
- double Vidurkis(double A[], int n);
- //---------------------------------------------
- int main()
- {
- double A[CMax];
- int n;
- Skaityti(A, n);
- cout << Vidurkis(A, n) << endl;
- return 0;
- }
- //---------------------------------------------
- void Skaityti(double A[], int & n)
- {
- double ugis;
- ifstream fd(CDfv);
- fd >> n;
- for(int i = 0; i < n; i++)
- {
- fd >> ugis;
- if(ugis < 0)
- A[i] = ugis * (-1);
- else
- A[i] = ugis;
- }
- }
- //---------------------------------------------
- double Vidurkis(double A[], int n)
- {
- double suma = 0;
- for(int i = 0; i < n; i++)
- suma = suma + A[i];
- return suma / n;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement