diff --git a/math/factorial/Lua/Factorial.lua b/math/factorial/Lua/Factorial.lua new file mode 100644 index 0000000000..3037433a74 --- /dev/null +++ b/math/factorial/Lua/Factorial.lua @@ -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)) \ No newline at end of file