Advertisement
Guest User

Untitled

a guest
Jun 25th, 2018
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.74 KB | None | 0 0
  1. #include <iostream>
  2. #include <ctime>
  3. using namespace std;
  4.  
  5. double wariancja( double *tab, int ileElementow){
  6. double m = 0;
  7. double suma = 0;
  8. double s = 0;
  9. double suma2 = 0;
  10. double k = 1/ileElementow;
  11.  
  12. for (int i=0; i<ileElementow; i++){
  13. suma += *(tab +i);
  14. }
  15. m = suma/ileElementow;
  16.  
  17. for (int j=0; j<ileElementow; j++){
  18. suma2 += (*(tab+j) - m) * (*(tab+j) - m);
  19. }
  20. s = k*suma2;
  21. cout << s;
  22. return s;
  23. }
  24.  
  25. int main() {
  26. int dlugosc = 0;
  27. srand(time(NULL));
  28. dlugosc = rand()%10+1;
  29. double tab[dlugosc];
  30.  
  31. for (int i=0; i<dlugosc; i++){
  32. tab[i] = rand()%20+1;
  33. }
  34.  
  35. wariancja(tab, dlugosc);
  36.  
  37. return 0;
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement