Sunday, 28 February 2016

Recursion - Week 6






This week was all about recursion and its usage. Though, the time taken by recursion might be more than the usual loops, it is easier to apply for complex problems.

The function factorial above is made through recursion. Recursion and loops both can be controlled by the programmer(interface).

Here are some rules about factorials, If n = 0 then n! = 1 If n > 0 then n! = 1 x 2 x 3 x ... x n
For example, let's look at the factorial of the number 7:
7! = 7*6*5*4*3*2*1


Let's look at a program which calculates the factorial of any number entered by the user, by method of recursion.

No comments:

Post a Comment