Andy Patrachari
Spring 2011
Recursive Functions
Recursion is a process by which a program tends to repeat itself multiple times until a specific criterion is
satisfied (decided by the programmer). A function that calls itself repeatedly is called as a recursive
function. Recursion is a power tool available in computers that helps programming certain aspects
simpler. Some examples where recursion can be used include calculating the factorial of a number,
calculating sum of all the numbers from 1 to a specific user entered value, all the various summation and
series type calculations in mathematics, etc. The sample function below illustrates the application of
recursion (recursive functions) to calculate the sum of all the integer numbers starting from 1 and going
to a particular user entered value (n), say 5.
Before looking at the actual program, let’s take a look at the actual mathematics (and logic) behind the
calculation. Let us represent sum of all the numbers from 1 to ‘n’ as Sum_n(n).
This preview has intentionally blurred sections. Sign up to view the full version.
View Full Document
This is the end of the preview.
Sign up
to
access the rest of the document.
 Spring '08
 staff
 Recursion, Calculation, Andy Patrachari, Sum_n

Click to edit the document details