Guest User

Untitled

a guest
Jan 21st, 2018
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.62 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <math.h>
  4.  
  5. const int N=200;
  6. double x[N];
  7. double xs;
  8. double l=1.0;
  9.  
  10. double p=0.5;
  11.  
  12. int main(int argc, char **argv)
  13. {
  14.     unsigned int i=0, j=0;
  15.     double a=0;
  16.     double xn, xx;
  17.    
  18.    
  19.    
  20.     for(i=1; i<=2e6; i++){
  21.         xn=0;
  22.         xx=0;
  23.         //a =(int)(((double)rand()/RAND_MAX)/p)*2-1;
  24.         for(j=0; j<N; j++){
  25.             a=(double)rand()/RAND_MAX;
  26.        
  27.             if(a<p) a=-l;
  28.             else a=+l;
  29.        
  30.             x[j]+=a;
  31.             xn+=x[j];
  32.         }
  33.        
  34.         for(j=0;j<N;j++){
  35.             xx+=pow((x[j]-xn), 2); 
  36.         }
  37.        
  38.         xx=1/N*sqrt(xx);
  39.         xs+=x[0];
  40.         printf("%d %lf %lf %lf\n", i, xs/i, xn/N, xx);
  41.        
  42.     }
  43.    
  44.     return 0;
  45. }
Add Comment
Please, Sign In to add comment