fork download
  1. #include <time.h>
  2. #include <stdlib.h>
  3. #include <stdio.h>
  4. #include <math.h>
  5.  
  6. int main ( int argc, char *argv[] )
  7. {
  8.  
  9. int number_of_steps = 30;
  10. int repetition = 6500000;
  11. int distance = 0;
  12. int total_distance = 0;
  13. double expected_distance;
  14. int i, j;
  15.  
  16. srand(time(NULL));
  17.  
  18. for ( i = 0; i < repetition; i++ ) {
  19.  
  20. for ( j = 0; j < number_of_steps; j++) {
  21. distance += rand() & 1 ? -1 : 1;
  22. }
  23.  
  24. total_distance += distance * distance;
  25. distance = 0;
  26.  
  27. }
  28.  
  29. expected_distance = sqrt((float) total_distance / repetition);
  30.  
  31. printf ( "%g\n", expected_distance );
  32. return EXIT_SUCCESS;
  33. } /* ---------- end of function main ---------- */
Time limit exceeded #stdin #stdout 5s 2244KB
stdin
Standard input is empty
stdout
Standard output is empty