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:

Captura de pantalla 2016-04-07 a las 14.13.26

In this code, you’ll need also another function for a factorial because de euler number has this formula:  Captura de pantalla 2016-04-07 a las 14.19.44

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”.

Here’s my GitHub link.
https://github.com/antonioangelm24/TC101/blob/master/Quiz%204

 


One response to “Quiz 4

Responder

Introduce tus datos o haz clic en un icono para iniciar sesión:

Logo de WordPress.com

Estás comentando usando tu cuenta de WordPress.com. Cerrar sesión /  Cambiar )

Google photo

Estás comentando usando tu cuenta de Google. Cerrar sesión /  Cambiar )

Imagen de Twitter

Estás comentando usando tu cuenta de Twitter. Cerrar sesión /  Cambiar )

Foto de Facebook

Estás comentando usando tu cuenta de Facebook. Cerrar sesión /  Cambiar )

Conectando a %s