Approximation of e P11916


Statement
 

pdf   zip

html

The Taylor series of the function ex is

ex
 
i ≥ 0
 
xi
i!
  .

Note that this series has an infinite number of terms. However, for any x we can get an approximation of ex by adding some of the first terms of the series (of course, the more terms, the better the result). In particular, chosing x = 1 gives us a method to compute e ≃ 2′71828182845904523536:

e = 
 
i ≥ 0
 
1
i!
  .

Write a program that, for every given natural number n, prints the approximation of e that we get by adding the n first terms of the series above.

Input

Input consists of several natural numbers n between 0 and 20.

Output

For every given n, print with 10 digits after the decimal point the approximation of e that we get by adding the n first terms of the series above.

Observation

Because of overflow reasons, do all the computations for this exercise using real numbers.

Public test cases
  • Input

    0
    1
    3
    20
    

    Output

    With 0 term(s) we get 0.0000000000.
    With 1 term(s) we get 1.0000000000.
    With 3 term(s) we get 2.5000000000.
    With 20 term(s) we get 2.7182818285.
    
  • Information
    Author
    Salvador Roura
    Language
    English
    Translator
    Carlos Molina
    Original language
    Catalan
    Other languages
    Catalan
    Official solutions
    C++ Java Python
    User solutions
    C C++ Java Python