-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathc.c
39 lines (29 loc) · 793 Bytes
/
c.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
/* run with `gcc c.c -Wall -std=c90 -o c` */
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
int main() {
long long iterations;
time_t t;
printf("Number of iterations: ");
scanf("%llu", &iterations);
/* initializes pseudo random number generator */
srand((unsigned) time(&t));
int sum_total;
float temp;
sum_total = 0;
/* for loop manual */
long long i = 0;
while (i < iterations) {
temp = 0;
while (temp < 1) {
/* get random float */
temp += ((float)rand()/(float)(RAND_MAX));
sum_total++;
}
i++;
}
/* printf("%llu %llu\n", sum_total, iterations); */
printf("e = %lf\n", ((double)sum_total) / iterations);
return(0);
}