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