Advertisement
Holek

Untitled

May 20th, 2017
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.54 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. using namespace std;
  4. double srednia_nzer(const vector<double> & t){
  5. int i;
  6. int rozmiar = t.capacity();
  7. int n_zer=0;
  8. double suma =0;
  9. for(i=0;i<rozmiar;i++){
  10. if(t[i] !=0) {
  11. suma += t[i];
  12. n_zer++;
  13. }
  14. }
  15. suma = suma/n_zer;
  16. return suma;
  17. }
  18. int main()
  19. {
  20. vector<double> a;
  21. a.reserve(5);
  22. a[0] = 9;
  23. a[1] = 10;
  24. a[2] = 0;
  25. a[3] = 10;
  26. a[4] = 10;
  27. cout << srednia_nzer(a)<< endl;
  28. return 0;
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement