Skip to content

Commit acce30e

Browse files
authored
Add Fibonacci in Tcl (#5055)
1 parent 6fa3ca7 commit acce30e

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

archive/t/tcl/fibonacci.tcl

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
proc usage {} {
2+
puts "Usage: please input the count of fibonacci numbers to output"
3+
exit 1
4+
}
5+
6+
if {$argc != 1} { usage }
7+
8+
set count [lindex $argv 0]
9+
10+
if {![string is integer -strict $count] || $count < 0} { usage }
11+
12+
set a 1
13+
set b 1
14+
15+
for {set i 1} {$i <= $count} {incr i} {
16+
puts "$i: $a"
17+
18+
set next [expr {$a + $b}]
19+
set a $b
20+
set b $next
21+
}

0 commit comments

Comments
 (0)