In this article we are going to see the create a program for factorial in F#, normally create a Factorial means takes four to five line of code, but in F# it is simple in one line we can write that.
rec is the keyword makes the function specify that is recursively called
rec is the keyword makes the function specify that is recursively called
open System
printfn "Factorial"
let rec factorial x = if x=0 then 1 else x * factorial(x-1)
Console.WriteLine(factorial(5))
Console.ReadKey()
Output:
Factorial
120
No comments:
Post a Comment