fork(1) download
  1. #include <iostream>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. #include <math.h>
  5. #include <time.h>
  6. using namespace std;
  7.  
  8. const int A=0;
  9. const int B=10000;
  10. const int N_int=10;
  11. const int N=100;
  12. const int Step=(B-A)/N_int;
  13.  
  14. int f(){ return rand()%(B-A) + A; }
  15.  
  16. int main(){
  17. double Xi = 0;
  18. unsigned nCount[N_int];
  19. srand(time(NULL));
  20. memset( nCount, 0, sizeof(nCount) );
  21. for( int i=0;i<N;++i ){
  22. ++nCount[ f()/Step ];
  23. }
  24. for( int i=0;i<N_int;++i ) cout <<nCount[i] << " ";
  25. cout << endl;
  26. double dPTeor = 1.0/N_int;
  27. cout << dPTeor << endl;
  28. for( int i=0;i<N_int;++i ){
  29. cout << 1.0*nCount[i]/N << " ";
  30. Xi+=pow(dPTeor - 1.0*nCount[i]/N, 2.0) / dPTeor;
  31. }
  32. cout << endl << Xi*N_int << endl;
  33. }
Success #stdin #stdout 0s 3296KB
stdin
Standard input is empty
stdout
16 13 8 10 8 11 15 7 6 6 
0.1
0.16 0.13 0.08 0.1 0.08 0.11 0.15 0.07 0.06 0.06 
1.2