summaryrefslogtreecommitdiff
path: root/659/CH9/EX9.16/topic9_16.sci
diff options
context:
space:
mode:
Diffstat (limited to '659/CH9/EX9.16/topic9_16.sci')
-rwxr-xr-x659/CH9/EX9.16/topic9_16.sci18
1 files changed, 18 insertions, 0 deletions
diff --git a/659/CH9/EX9.16/topic9_16.sci b/659/CH9/EX9.16/topic9_16.sci
new file mode 100755
index 000000000..080bd5be4
--- /dev/null
+++ b/659/CH9/EX9.16/topic9_16.sci
@@ -0,0 +1,18 @@
+// Topic 9.16 RECURSION
+// Page no. 288
+//Write a program to calculate factorial of a number using recursion
+function[fact1]=factorial1(n)
+ fact1=-1
+ if(n<0) then
+ disp("Please enter positive value[i.e. 0 or greater than 0] ");
+ return; //Quits the current function
+ end
+ if((n==0)|(n==1)) then
+ fact1=1;
+ else
+ fact1=n*factorial1(n-1); //recursive call to factorial1()
+ end
+endfunction
+n=input("Enter number:");
+//calling factorial1() function inside printf()
+printf("Factorial of %d = %d",n,factorial1(n)); \ No newline at end of file