### Quiz 4

We created a function called euler_calc with a single parameter precision. The value of precision is used to determine when to stop calculating. Your calculation will stop when the two consecutive values estimating e differ by less than precision. For example: In this code, you’ll need also another function for a factorial because de euler number has this formula: so it is 1/factorial with a limit until when the two consecutive values estimating e differ by less than precision. And the precision will be as short or long as you want.

If you calculate the e number on a scientific calculator, the number will be 2.718281828.

First you write the euler function like this euler_cacl (float precision) , with the 2 floats variables, e for the answer, prev for the previous e value; and 1 int = n. Then there’s the loop Do While, and will do e = e / (1/factorial(n)).

The factorial function must be like this, because you can’t have 0* n, because it will return you 0, and you can’t have a 0 as a divisor.

For the While in the euler function, must be while ((e-prev)>precision). The the loop will stop and you will have the answer which is “e”.

1. Daniel Amaro dice: