• + 2 comments

    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) } }