We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
Evaluating e^x
Evaluating e^x
Sort by
recency
|
208 Discussions
|
Please Login in order to post a comment
Haskel code
Body flanges play an important role in industries such as oil and gas, petrochemicals, power generation, and more. Their primary function is to connect different parts of a piping system, facilitating the flow of fluids and gases in the shells of tanks, pressure vessels, and heat exchangers.
My working scala code :
object Solution { def main(args: Array[String]):Unit = { val stdin = scala.io.StdIn val n = stdin.readLine.trim.toInt for (nItr <- 1 to n) { val x = stdin.readLine.trim.toDouble println(((make(x) * 10000).round).toDouble / 10000.toDouble) } }
def sum(a: Double, b: Double): Double = return a + b;
def make(x: Double): Double = { return Range(0, 10).map(number => Math.pow(x, number) / factorial(number)).sum
}
def factorial(x: Double): Double = { if (x == 0) return 1 else return x * factorial(x - 1) } }
Using unbounded arrays