Advertisement
Guest User

Untitled

a guest
Oct 9th, 2012
29
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
F# 0.54 KB | None | 0 0
  1. open System
  2.  
  3. let rec sumupto n = if n=0 then 0 else n + sumupto (n-1)
  4. let rec factorial n = if n=0 then 1 else n * factorial (n-1)
  5. let div n : float = float (sumupto n)/float (factorial n)
  6.  
  7. let read() =
  8.     printfn "Please enter a number."
  9.     System.Console.ReadLine()
  10. let convert (source : string) =
  11.     try System.Int32.Parse(source)
  12.     with :? System.FormatException ->
  13.         printfn "'%s' is not a number!" source;
  14.         exit 1
  15.  
  16. let num1 : int = read() |> convert
  17.  
  18. printfn "result=%f" ( div num1 )
  19.  
  20. Console.ReadLine()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement