Instantly share code, notes, and snippets.

Embed
What would you like to do?
#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