Subscribed unsubscribe Subscribe Subscribe

TI-Nspire & Lua / 再帰呼び出し / 階乗を求める

Nspired Lua

f:id:ti-nspire:20170125183044p:plain:h315

.lua

function factorial(n)
   if n == 0 then
      return 1 
   else 
      return n * factorial(n - 1) 
   end
end

print(factorial(0))
print(factorial(1))
print(factorial(10))
print(factorial(69))

参考:
Programming in Lua, Fourth Edition
p.3

Remove all ads