Skip to content

Instantly share code, notes, and snippets.

@keyvanakbary
Created January 14, 2015 14:53
Show Gist options
  • Select an option

  • Save keyvanakbary/e58efdd7fbb77dbe78f4 to your computer and use it in GitHub Desktop.

Select an option

Save keyvanakbary/e58efdd7fbb77dbe78f4 to your computer and use it in GitHub Desktop.
(defn factorial [n]
(if (pos? n) (* n (factorial (dec n))) 1))
(defn calculate-e [x precision]
(if (pos? precision)
(+ (/ (Math/pow x precision) (factorial precision))
(calculate-e x (dec precision)))
1))
(dotimes [n (Integer/parseInt (read-line))]
(println (calculate-e (Float/parseFloat (read-line)) 9)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment