Estimating e!

This week’s activity consisted of creating a function that would calculate the number e with the precision determined by the user.

The formula to do it is this one:

{\displaystyle e=1+{\frac {1}{1}}+{\frac {1}{1\cdot 2}}+{\frac {1}{1\cdot 2\cdot 3}}+\cdots }

which is the same as this:

e = \frac{1}{0!} + \frac{1}{1!} + \frac{1}{2!} + \frac{1}{3!} + \cdots

My teacher Ken explained to me that when the difference between two consecutive numbers is less or equal to the precision, the program should stop and return the answer.

e

Notice how in my function, I’m calling another function, factorial.

It runs like this:

e_run

One thought on “Estimating e!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s