Advertisement
JosepRivaille

P65171: Control C202B

Feb 26th, 2015
996
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.39 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4.  
  5. //Pre: Llegeix un natural n i n nombres
  6. //Post: En calcula la varianรงa
  7. int main() {
  8.   cout.setf(ios::fixed);
  9.   cout.precision (2);
  10.   double n, x, u = 0, v = 0;
  11.   cin >> n;
  12.   for (int i = n; i != 0; --i) {
  13.     cin >> x;
  14.     u = u + x*x;
  15.     v = v + x;
  16.   }
  17.   v = v*v;
  18.   u = (1 / (n-1))*u;
  19.   v = (1 / (n*(n-1)))*v;
  20.   cout << u-v << endl;
  21. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement