1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
# Copyright (C) 2008, Parrot Foundation. print("Please enter number: ") x = read() sub factorial(n) ## test for < 2 because all numbers are represented by ## floating-point numbers, and equality checks on those ## do not work (yet?) if n < 2 then return 1 else return n * factorial(n - 1) end end print("factorial of ", x, " is: ", factorial(x)) |