Difference between Recursion and Iteration | -- -- - Recursion -- -- - method to find factorial of given number ; recursion call ; -- -- - Iteration -- -- - Method to find the factorial of a given number ; using iteration ; Driver method
def factorialUsingRecursion ( n ) : NEW_LINE INDENT if ( n == 0 ) : NEW_LINE INDENT return 1 ; NEW_LINE DEDENT return n * factorialUsingRecursion ( n - 1 ) ; NEW_LINE DEDENT def factorialUsingIteration ( n ) : NEW_LINE INDENT res = 1 ; NEW_LINE for i in range ( 2 , n + 1 ) : NEW_LINE INDENT res *= i ; NEW_LINE DEDENT return res ; NEW_LINE DEDENT num = 5 ; NEW_LINE print ( " Factorial ▁ of " , num , " using ▁ Recursion ▁ is : " , factorialUsingRecursion ( 5 ) ) ; NEW_LINE print ( " Factorial ▁ of " , num , " using ▁ Iteration ▁ is : " , factorialUsingIteration ( 5 ) ) ; NEW_LINE