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