If you shop at Amazon anyway, consider using
this link. We receive a few cents from each purchase.
If you benefit from the website, in terms of
knowledge, entertainment value, or something otherwise useful,
consider making a donation via PayPal to help defray the
costs. (No PayPal account necessary to donate via credit
card.) Transaction is secure.
e-mail with your comments about this program (or anything else).
Recursion is a programming technique
that can accomplish a lot with a little bit of code. Because recursive
procedures call themselves, their operation seems like magic. Here
are a couple of recursive functions - one to calculate factorials and one
to calculate Fibonacci numbers.
Example 1: Factorials
N factorial for a positive integer N is
defined as the product of the integers 1 through N. It is usually written
If N=1 then result:=1
Example 2: Fibonacci Numbers
numbers are members of an infinite series of integers in which the first two numbers are 1,
and each number after the 2nd is the sum of the two preceding numbers (1, 1, 2,
3, 5, 8, 13....). Here's a
function that returns the Nth Fibonacci number:
If N<=2 then result:=1
Here is a program that
calculates integer powers of a real number. Recursion is one of 4
techniques tested. The program will also introduce you to techniques for
accurately measuring program run times. Click
here to download source code for IntPowerDemo.