Simple and Efficient C Program to Compute the Mathematic Constant E (Euler’s number)


e (Euler’s number) is a mathematical constant that is the value of tex_b2d5cf4b8adb26b1abe4b62edc63408e Simple and Efficient C Program to Compute the Mathematic Constant E (Euler's number) algorithms c / c++ math when n is approaching infinity. Alternatively, it can be expressed as tex_e8898caa1c87be37fdd1d296a27f4fb6 Simple and Efficient C Program to Compute the Mathematic Constant E (Euler's number) algorithms c / c++ math when t is approaching zero.

It can be expressed as the sum of infinite series:

e Simple and Efficient C Program to Compute the Mathematic Constant E (Euler's number) algorithms c / c++ math

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.

compute-e-in-c Simple and Efficient C Program to Compute the Mathematic Constant E (Euler's number) algorithms c / c++ math

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 words
Last Post: Filter out Spam Words using PHP Function
Next Post: Teaching Kids Programming - Reverse a Graph (Adjacency List)

The Permanent URL is: Simple and Efficient C Program to Compute the Mathematic Constant E (Euler’s number)

Leave a Reply