csansoon

P2.13 P65171 Control C202B

Sep 21st, 2018
181
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.40 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4.  
  5. // [1/(1-n)] * x2   -   [1/(n(n-1))] * (x^2)
  6.  
  7.  
  8.  
  9. int main () {
  10.    
  11.     cout.setf(ios::fixed);
  12.     cout.precision(2);
  13.    
  14.    
  15.     double n, x, x1, x2;
  16.     cin >> n;
  17.     x=0;
  18.     x1=0;
  19.     x2=0;
  20.     while (cin >> x) {
  21.         x1 += x;
  22.         x2 += (x*x);
  23.     }
  24.     x1 = (x1*x1)/(n*(n-1));
  25.     x2 /= (n-1);
  26.     cout << (x2-x1) << endl;
  27. }
Advertisement
Add Comment
Please, Sign In to add comment