factorial.lua 209 B

123456789101112131415
  1. #!/usr/bin/lua
  2. --defines a factorial program
  3. function fact(n)
  4. if n == 0 then
  5. return 1
  6. else
  7. return n * fact (n-1)
  8. end
  9. end
  10. print ("enter a number: ")
  11. a = io.read("*number")
  12. print(fact(a))