#include<stdio.h> #include<stdlib.h> int main(int argc, char const *argv[]) { unsigned i,j,k=0,n=1e8; for(i=0;i<n;i++){ for(j=0;j<RAND_MAX;j+=rand()) k++; } printf("e=%f ", (double)k/n); return 0; }
gcc e.c -O3&&./a.out
e=2.718259
#include<stdio.h> #include<stdlib.h> int main(int argc, char const *argv[]) { unsigned i,j,k=0,n=1e8; for(i=0;i<n;i++){ for(j=0;j<RAND_MAX;j+=rand()) k++; } printf("e=%f ", (double)k/n); return 0; }
gcc e.c -O3&&./a.out
e=2.718259