14 lines
325 B
Text
14 lines
325 B
Text
factorial (n) iterative:
|
|
p =: 1
|
|
?# i =: from 2 upto n \ does nothing if n < 2
|
|
p =* i
|
|
:> p
|
|
factorial (n) recursive:
|
|
? n <= 1
|
|
:> 1
|
|
:> n * factorial recursive n-1
|
|
\ test code
|
|
main(parms):+
|
|
arg =: string parms[1] as integer else 100
|
|
print factorial arg iterative
|
|
print factorial arg recursive
|