# Evaluating e^x – HackerRank Solution

In this post, we will solve Evaluating e^x HackerRank Solution. This problem (Evaluating e^x) is a part of HackerRank Functional Programming language.

Contents

The series expansion ofÂ exÂ is given by:

1 + x + x2/2! + x3/3! + x4/4! + . . . . . .

EvaluateÂ exÂ for given values ofÂ Â by using the above expansionÂ for the firstÂ 10Â terms.

## Input Format

The first line contains an integerÂ N, the number of test cases.
NÂ lines follow. Each line contains a value ofÂ xÂ for which you need to output the value ofÂ exÂ using the above series expansion. These input values have exactlyÂ 4Â decimal places each.

## Output Format

OutputÂ NÂ lines, each containing the value ofÂ ex, computed by your program.

## Constraints

• 1 <= N <= 50
• -20.00 <= x <= 20.00
• Var,Â ValÂ in Scala andÂ defÂ andÂ defnÂ in Clojure are blocked keywords. The challenge is to accomplish this without either mutable state or direct declaration of local variables.

Sample Input

``````4
20.0000
5.0000
0.5000
-0.5000``````

Sample Output

``````2423600.1887
143.6895
1.6487
0.6065``````

Explanation

The output has the computed values ofÂ exÂ corresponding to each test case. They are correct up toÂ 4Â decimal places and on separate lines.

=== codingbroz.com_728x90 (#88864) ===
=== codingbroz.com_728x90 (#88864) ===

Scoring

All test cases carry an equal weight in the final score. For your solution to pass a given test case, all the values ofÂ exÂ computed by you must be withinÂ +/-0.1Â of the expected answers. This tolerance level has been kept to account for slightly different answers across different languages.

## Solution – Evaluating e^x – HackerRank Solution

```import Control.Applicative
import System.IO

eee :: Double -> Double -> Double
eee 1 x = x + 1
eee n x = ((x**n) / (product [1..n])) + (eee (n-1) x)

main :: IO ()
main = do
n_temp <- getLine
let n = read n_temp :: Int
forM_ [1..n] \$ \a0  -> do
x_temp <- getLine
let x = read x_temp :: Double
print (eee 9 x)

getMultipleLines :: Int -> IO [String]

getMultipleLines n
| n <= 0 = return []
| otherwise = do
x <- getLine
xs <- getMultipleLines (n-1)
let ret = (x:xs)
return ret
```

Note: This problem (Evaluating e^x) is generated by HackerRank but the solution is provided by CodingBroz. This tutorial is only for Educational and Learning purpose.