Recursive Function
• A function calling itself is called recursive function
• It is same as the recursive function in mathematics
• A factorial is de ned in terms of factorial only ,therefore it is called recursive function
Ex : n ! = 1 * 2 * 3 * 4 * 5 ….. * n
5! = 5 * 4 * 3 * 2 * 1
5! = 5 * 4!
n! = n * ( n -1)
• In maths recursive function is also de ne as
fact( n ) = { 1 if n=0
n * fact(n-1) if n>0
• In python we can write the same thing as
Ex:
def fact ( n ) :
If n == 0 :
return 1
else :
Return n * fact ( n-1)
Output :
fi
fi