- Notifications
You must be signed in to change notification settings - Fork91
Declaring a simple recursive function
CodingUnit edited this pageNov 30, 2011 ·2 revisions
Category: Recursion
Description: Declaring a simple recursive function
Code:
def SampleRec1() {def fib(n) {if (n <2)1else fib(n-1)+ fib(n-2) }foreach (iin $[0..10])WriteLine($"fib$i= {0}", fib(i))}SampleRec1()
Execution Result:
fib1 =1 fib2 =2 fib3 =3 fib4 =5 fib5 =8 fib6 =13 fib7 =21 fib8 =34 fib9 =55 fib10 =89
[Copyright ©](Terms of use, legal notice)