e (Euler’s number) is a mathematical constant that is the value of when n is approaching infinity. Alternatively, it can be expressed as when t is approaching zero.
It can be expressed as the sum of infinite series:
It is an irrational number. And can be computed via the following C code:
1 2 3 4 5 6 7 8 9 10 11 12 | #include <stdio.h> int main() { int N = 9009; int n = N, x; int a[9009]; while (--n) { a[n] = 1 + 1 / n; } for(; N > 9; printf("%d",x)) { for (n = N--; --n; a[n] = x%n, x = 10 * a[n - 1] + x / n); } } |
#include <stdio.h> int main() { int N = 9009; int n = N, x; int a[9009]; while (--n) { a[n] = 1 + 1 / n; } for(; N > 9; printf("%d",x)) { for (n = N--; --n; a[n] = x%n, x = 10 * a[n - 1] + x / n); } }
The C computes the e constant and store then in a static array.
Save above C code in e.c and compile it using the following command:
1 | gcc -o e e.c |
gcc -o e e.c
And then the C program will be compiled into an Linux executable e which you can run to get the value of the Euler’s e constant.
–EOF (The Ultimate Computing & Technology Blog) —
GD Star Rating
loading...
352 wordsloading...
Last Post: Filter out Spam Words using PHP Function
Next Post: Teaching Kids Programming - Reverse a Graph (Adjacency List)