-
Notifications
You must be signed in to change notification settings - Fork 93
Declaring a simple recursive function
CodingUnit edited this page Nov 30, 2011
·
2 revisions
-
Category: Recursion
-
Description: Declaring a simple recursive function
-
Code:
def SampleRec1()
{
def fib(n) { if (n < 2) 1 else fib(n - 1) + fib(n - 2) }
foreach (i in $[0..10])
WriteLine($"fib $i = {0}", fib(i))
}
SampleRec1() Execution Result:
fib 1 = 1
fib 2 = 2
fib 3 = 3
fib 4 = 5
fib 5 = 8
fib 6 = 13
fib 7 = 21
fib 8 = 34
fib 9 = 55
fib 10 = 89 - Copyright
Samples used from “F# 3.0 Sample Pack” (http://fsharp3sample.codeplex.com/) at Codeplex OpenSource Community for non-commercial usage. All copyrights and authorship on materials this publication based on, is belongs to Microsoft corp. Copyright © 2006-2011 Microsoft Corporation, . All rights reserved. Copyright and autorship for materials in Nemerle language belongs to Nemerle Project Team. Copyright © 2008-2011 Nemerle Project Team. All rights reserved.