Quiz #4

Hello everyone,

Today I’m going to share with you my quiz #4.

Instructions: 

The number e is an important mathematical constant that is the base of the natural logarithm. It is approximately equal to 2.71828,[1] and is the limit of (1 + 1/n)n as n approaches infinity, an expression that arises in the study of compound interest. It can also be calculated as the sum of the infinite series.

Create 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 (remember to use absolute value when calculating the difference between two values here).

 

And here is my code:

2016-03-21 (3)2016-03-21 (4)

The Euler number is very important in the math area and we can calculate it with this formula:

e =  displaystylesumlimits_{n = 0}^{ infty} dfrac{1}{n!} = 1 + frac{1}{1} + frac{1}{1cdot 2} + frac{1}{1cdot 2cdot 3} + cdots

Image link

All the stuff is the same as the last posts but the new thing here is that we are including a new library for us.

With the <iomanip> library  we can use SETPRECISION. It can help us to give an answer exactly with the precision that the user wants and that is what I made with the code. An example of SETPRECISION is:

// setprecision example
#include <iostream>
#include <iomanip>
using namespace std;

int main () {
  double f =3.14159;
  cout << setprecision (5) << f << endl;
  cout << setprecision (9) << f << endl;
  return 0;
}

The execution of this example shall display:
  3.1416
3.14159

Example Link

It is a great tool for the one that really are especial with the specific results in math. Practice and it’ll become easier for you.

This other web site help me to know more about euler number.

See you

my next post friends.

Top image: flickr photo by cogdogblog https://flickr.com/photos/cogdog/6348960813 shared under a Creative Commons (BY) license

 

 

CC BY-SA 4.0 Quiz #4 by sercho93 is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.