Recursion Function:-
जब function स्वयं को call करता है तो उसे recursion function के नाम से जाना जाता है
def fun_name(): ………. ………. ………. ………. fun_name() ———–> recursion function fun_name() |
1: wap to print 1 to 10 number using recursion functions
2: wap to print all even numbers between 1 to 50 using recursion function.
3: wap to find factorial of any number using recursion function
1. def num(a): if a<=10: print(a,” “,end=” “) a=a+1 num(a) num(1)
|
2. def num(a): if a<=50: if a%2==0: print(a,” “,end=” “) a=a+1 num(a) num(1) |
3. def factorial(n): if n == 1: return n else: return n*factorial(n-1) num = int(input(“Enter any number: “)) if num < 0: print(“Factorial does not exist for negative numbers”) elif num == 0: print(“The factorial of 0 is 1”) else: print(“The factorial of”, num, “is”, factorial(num)) |