Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <ctime>
- using namespace std;
- double wariancja( double *tab, int ileElementow){
- double m = 0;
- double suma = 0;
- double s = 0;
- double suma2 = 0;
- double k = 1/ileElementow;
- for (int i=0; i<ileElementow; i++){
- suma += *(tab +i);
- }
- m = suma/ileElementow;
- for (int j=0; j<ileElementow; j++){
- suma2 += (*(tab+j) - m) * (*(tab+j) - m);
- }
- s = k*suma2;
- cout << s;
- return s;
- }
- int main() {
- int dlugosc = 0;
- srand(time(NULL));
- dlugosc = rand()%10+1;
- double tab[dlugosc];
- for (int i=0; i<dlugosc; i++){
- tab[i] = rand()%20+1;
- }
- wariancja(tab, dlugosc);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement