fork download
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <math.h>
  4.  
  5. double f(double x, double y) { return sqrt(x * x + y * y); }
  6.  
  7. int g(int s, int n) {
  8. return (n == 0) ? s
  9. : (f((double)rand() / RAND_MAX, (double)rand() / RAND_MAX)) < 1.0
  10. ? g(s + 1, n - 1)
  11. : g(s, n - 1);
  12. }
  13.  
  14. #define SEED 31415926
  15. #define N 100000
  16. int main() {
  17. srand(SEED);
  18. printf("%f\n", 4.0 * g(0, N) / N);
  19. return 0;
  20. }
  21. /* end */
  22.  
Success #stdin #stdout 0.02s 1720KB
stdin
Standard input is empty
stdout
3.141400