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
< ? php function factorialUsingRecursion ( $ n ) { if ( $ n == 0 ) return 1 ; return $ n * factorialUsingRecursion ( $ n - 1 ) ; } function factorialUsingIteration ( $ n ) { $ res = 1 ; for ( $ i = 2 ; $ i <= $ n ; $ i ++ ) $ res *= $ i ; return $ res ; } $ num = 5 ; print ( " Factorial ▁ of ▁ " . $ num . " ▁ using ▁ Recursion ▁ is : ▁ " . factorialUsingRecursion ( 5 ) . " STRNEWLINE " ) ; print ( " Factorial ▁ of ▁ " . $ num . " ▁ using ▁ Iteration ▁ is : ▁ " . factorialUsingIteration ( 5 ) . " STRNEWLINE " ) ; ? >