Skip to content

Commit

Permalink
Added Factorial with Lua
Browse files Browse the repository at this point in the history
  • Loading branch information
Pedro committed Oct 31, 2017
1 parent 4e519bd commit 40ffdfd
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions math/factorial/Lua/Factorial.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
--recursive function to factorial
function fat(num)
--if number < 0 dont have factorial
if num<0 then
return "Dont have factorial"
end
--factorial of 1 and 0 is 1
if num == 1 or num == 0 then
return 1
end
--factorial of num > 1 is num*factorail of num-1
return num*fat(num-1)


end
--print factorial of 5
print(fat(4))

0 comments on commit 40ffdfd

Please sign in to comment.