Advertisement
ItsMeLucifer

Zad2 Simin JPO19

Jun 23rd, 2019
409
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.61 KB | None | 0 0
  1. #include "pch.h"
  2. #include <iostream>
  3. #include <cmath>
  4.  
  5. using namespace std;
  6.  
  7. double wariancja(double * tab, int ileElementow) {
  8.     double suma=0;
  9.     for (int k = 0; k < ileElementow; k++) {
  10.         suma += *(tab + k);
  11.     }
  12.     double m = suma / ileElementow;
  13.     suma = 0;
  14.     for (int i = 0; i < ileElementow; i++) {
  15.         suma += pow((*(tab + i) - m),2.0);
  16.     }
  17.     return (1 / double(ileElementow))*suma;
  18. }
  19. int main()
  20. {
  21.     int elementy=20;
  22.     bool liczmin=false;
  23.     double * tab = new double[elementy];
  24.     for (int i = 0; i < elementy; i++) {
  25.         *(tab + i) = i;
  26.     }
  27.     double s2=wariancja(tab, elementy);
  28.     cout << s2;
  29.     return 0;
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement