Advertisement
Holek

Untitled

May 20th, 2017
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.03 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. #include <math.h>
  4. #include <iomanip>
  5.  
  6. using namespace std;
  7.  
  8. double srednia(const vector<double> & t){
  9. int rozmiar = t.capacity();
  10. int i;
  11. double suma =0;
  12. for(i=0;i<rozmiar;i++){
  13. suma+=t[i];
  14. }
  15. suma=suma/rozmiar;
  16. return suma;
  17.  
  18. }
  19. double moment(int stopien,const vector<double> & t, bool czy_centralny=false){
  20. int i;
  21. int rozmiar = t.capacity();
  22. double suma=0;
  23. if(czy_centralny==false) {
  24. for(i=0;i<rozmiar;i++){
  25. suma+=pow((double)t[i],stopien);
  26. }
  27. suma=suma/rozmiar;
  28. }
  29.  
  30. if(czy_centralny==true){
  31. double sre = srednia(t);
  32. for(i=0;i<rozmiar;i++){
  33. suma+=pow((double)(t[i]-sre),stopien);
  34. }
  35. suma=suma/rozmiar;
  36. }
  37.  
  38. return suma;
  39. }
  40.  
  41. int main()
  42. {
  43. vector<double> a;
  44. a.reserve(5);
  45. a[0] = 9;
  46. a[1] = 10;
  47. a[2] = 10;
  48. a[3] = 10;
  49. a[4] = 10;
  50. cout <<setprecision(20)<< moment(2,a, true) << endl;
  51. return 0;
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement