summaryrefslogtreecommitdiff
path: root/3808/CH5/EX5.2
diff options
context:
space:
mode:
Diffstat (limited to '3808/CH5/EX5.2')
-rw-r--r--3808/CH5/EX5.2/Ex5_2.sce17
1 files changed, 17 insertions, 0 deletions
diff --git a/3808/CH5/EX5.2/Ex5_2.sce b/3808/CH5/EX5.2/Ex5_2.sce
new file mode 100644
index 000000000..e7b9b38f6
--- /dev/null
+++ b/3808/CH5/EX5.2/Ex5_2.sce
@@ -0,0 +1,17 @@
+//Chapter 05: Induction and Recursion
+
+clc;
+clear;
+
+function fact = my_factorial(n)
+if n == 0
+ fact = 1
+else
+ fact = n * my_factorial(n-1)//recursive function call
+end
+return fact
+endfunction
+
+num=input("Enter the number whose factorial is to be found:")
+f=my_factorial(num)
+mprintf("The factorial of %d is %d",num,f)