Created
August 20, 2010 05:22
-
-
Save ihodes/539670 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <time.h> | |
#include <stdlib.h> | |
int main(int argc, char **argv){ | |
long iterations = atoi(argv[1]); | |
double sum = 0; | |
long ans, i, j = 0; | |
long seed = time((time_t *) NULL); | |
srand48(seed); | |
for(i = 0; i <= iterations; i++){ | |
for(j = 1, sum = 0; (sum += drand48()) <= 1.0; j++); | |
ans += j; | |
} | |
printf("Our estimate for e is %.10f.\n", (double) ans/iterations); | |
return 1; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment