summaryrefslogtreecommitdiff
path: root/lua/2.lua
diff options
context:
space:
mode:
Diffstat (limited to 'lua/2.lua')
-rwxr-xr-xlua/2.lua15
1 files changed, 15 insertions, 0 deletions
diff --git a/lua/2.lua b/lua/2.lua
new file mode 100755
index 0000000..a5a2374
--- /dev/null
+++ b/lua/2.lua
@@ -0,0 +1,15 @@
+function fact (n)
+ if n == 0 then
+ return 1
+ else
+ return n * fact(n-1)
+ end
+end
+
+print("enter a number: ")
+a = io.read("*n") -- Read a number
+if a < 0 then
+ print(a .. "negative")
+ return 1;
+end
+print(fact(a))