Pure Programmer
Blue Matrix


Cluster Map

Project: Calculate Euler's Number

You can calculate the value of [[E_(mathematical_constant)|Euler's Number]] (𝑒) using an infinite series that uses the factorial function.

`e = sum_(n=0)^oo 1/(n!)`

or

`e = 1 + 1/(1!) + 1/(2!) + 1/(3!) + 1/(4!) + 1/(5!) + ...`

where the factorial n! is:

`n! = 1*2*3*4*5*...*n`

Write a function to compute Euler's Number to a specified number of terms N that is passed to the function. Test the function with various values of N.

Output
$ perl CalculateEulersNumber.pl ℯ(1) = 2 ℯ(2) = 2.5 ℯ(3) = 2.66666666666667 ℯ(5) = 2.71666666666667 ℯ(10) = 2.71828180114638

Solution