/***date:2014.12.10***/
Recursive method: is the representative of rational thinking mode, according to the existing data and relations, gradually deduced and derived results.
Execution process: 1) solve the intermediate result according to the known result and relation.
2) Determine whether the requirements are met, and if not, continue to solve the intermediate results based on the known results and relationships; If the requirements are met, a correct answer is found.
In 13th century, the Italian mathematician Fibonacci's "Abacus Book" Records: Rabbit Litter problem.
A pair of two-month-old rabbits, each month can litter a pair, the rabbit two months after the monthly can also litter a pair, that is, January born, March began to be continuous litter. How many rabbits are there in a year after death?
#include <stdio.h>
#include <stdlib.h>
int Fibonacci (int n)
{
int r1,r2;
if (n = = 1 | | n = = 2)
{
return 1;
}
Else
{
R1 = Fibonacci (n-1);
r2 = Fibonacci (n-2);
return R1 + R2;
}
}
int main ()
{
int r,sum;
printf ("Recursive algorithm to solve the problem of rabbit litter: \ n");
printf ("Please enter cut-off time:");
scanf_s ("%d", &r);
sum = Fibonacci (r);
printf ("After%d months, the total can be bred into%d pairs of rabbits, the number of rabbits total%d. \ n", r,sum,2*sum);
System ("pause");
return 0;
}
Fibonacci Recursive algorithm