Advertisement
Guest User

Untitled

a guest
Jun 27th, 2017
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.23 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3.  
  4. using std::cin; using std::cout; using std::endl;
  5.  
  6. int main ()
  7. {
  8.     //Izracunajmo S_xx
  9.     std::vector<double> x{173,176,189,182,167,183,170,179,177,185,172,163,173,180,165,165,176,170,173,182,180,166,181,170,181,180,183,184,195,170};
  10.     double s(0), x_sr(0);
  11.     //Izracunajmo x_sr
  12.     for (int i=0; i<30; i++) {
  13.         x_sr=x_sr+x[i];
  14.     }
  15.     x_sr=x_sr/30;
  16.     cout << "x_sr: " << x_sr << endl;
  17.     for (int i=0; i<30; i++) {
  18.         s=s+(x_sr-x[i])*(x_sr-x[i]);
  19.         //cout << s << endl;
  20.     }
  21.     cout << "S_xx: " << s << endl;
  22.    
  23.     //Izracunajmo S_yy
  24.     std::vector<double> y{62,88,83,74,62,64,60,74,64,83,55,48,57,83,65,55,75,64,62,77,72,50,76,58,72,69,75,88,82,60
  25. };
  26.     s=0;
  27.     double y_sr(0);
  28.     //Izracunajmo y_sr
  29.     for (int i=0; i<30; i++) {
  30.         y_sr=y_sr+y[i];
  31.     }
  32.     y_sr=y_sr/30;
  33.     cout << "y_sr: " << y_sr << endl;
  34.     for (int i=0; i<30; i++) {
  35.         s=s+(y_sr-y[i])*(y_sr-y[i]);
  36.         //cout << s << endl;
  37.     }
  38.     cout << "S_yy: " << s << endl;
  39.  
  40.     //Izracunajmo S_xy
  41.     s=0;
  42.     for (int i=0; i<30; i++) {
  43.         s=s+(x_sr-x[i])*(y_sr-y[i]);
  44.         //cout << s << endl;
  45.     }
  46.     cout << "S_xy: " << s << endl;
  47.     return 0;
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement