Fibonacci numbers in Algol68
Example for versions
Algol68g-1.18.0,
Algol68toc-1.8
Analytic method
PROC analytic fibonacci = (INT n)INT:(
REAL sqrt 5 = sqrt(5);
REAL p = (1 + sqrt 5) / 2;
REAL q = 1/p;
ENTIER( (p**n + q**n) / sqrt 5 )
);
FOR i FROM 0 TO 16 WHILE
print(whole(analytic fibonacci(i),0));
# WHILE # i /= 16 DO
print(", ")
OD;
print(new line)
Comments
]]>blog comments powered by Disqus
]]>