2015-08-09 19:43:47 +00:00
|
|
|
|
2015-08-10 15:05:58 +00:00
|
|
|
VAR res : INT;
|
2015-08-09 19:43:47 +00:00
|
|
|
|
2015-08-10 11:55:52 +00:00
|
|
|
PUB main(x : INT) → c : INT
|
2015-08-10 14:37:16 +00:00
|
|
|
BEGIN
|
2015-08-12 10:15:47 +00:00
|
|
|
# factorial(10) → res;
|
|
|
|
fibonacci(7) → res;
|
2015-08-10 15:05:58 +00:00
|
|
|
END
|
|
|
|
|
|
|
|
PUB factorial(number : INT) → result : INT
|
|
|
|
BEGIN
|
|
|
|
IF number > 1 THEN
|
|
|
|
number * factorial(number - 1) → result;
|
2015-08-12 10:15:47 +00:00
|
|
|
ELSE
|
|
|
|
1 → result;
|
|
|
|
END
|
|
|
|
|
|
|
|
# Recursive test
|
|
|
|
PUB fibonacci(n : INT) → f : INT
|
|
|
|
BEGIN
|
|
|
|
IF n = 0 THEN
|
|
|
|
0 → f;
|
|
|
|
ELSEIF n = 1 THEN
|
|
|
|
1 → f;
|
|
|
|
ELSE
|
|
|
|
fibonacci(n - 1) + fibonacci(n - 2) → f;
|
2015-08-10 14:37:16 +00:00
|
|
|
END
|