We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 63e770e commit f268a4dCopy full SHA for f268a4d
1 file changed
archive/f/forth/fibonacci.fth
@@ -0,0 +1,17 @@
1
+: fibonacci ( n -- )
2
+ 0 1 rot 0 ?do \ prepare the stack and loop
3
+ tuck + \ calculate the next fibonacci number
4
+ i 1+ 0 .r ." : " \ print the current index
5
+ over 0 .r cr \ print the current fibonacci number
6
+ loop
7
+ 2drop ;
8
+
9
+: usage ( -- ) ." Usage: please input the count of fibonacci numbers to output" cr ;
10
11
+: main
12
+ argc @ 2 < if usage exit then
13
+ 1 arg s>number? 0= if usage exit else drop then
14
+ fibonacci ;
15
16
+main
17
+bye
0 commit comments