blob: 080bd5be4bc2076cfd3d06e2e3b85dcf026a9481 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
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));
|