Fibonacci Recursive Algorithm
/*** Date: 2014.12.10 ***/
// Recursive algorithm: a representative of the rational thinking model. Based on the existing data and relationships, the results are derived gradually.
// Execution Process: 1) Solve intermediate results based on known results and relationships.
//// // 2) Determine whether the requirements are met. If the requirements are not met, the intermediate results are solved based on known results and links. If the requirements are met, a correct answer is found.
// In the 13th century, the Italian mathematician Fibonacci's abacus recorded the question of rabbit litter.
// A pair of two-month-old rabbits can have a pair of babies every month, and a pair of rabbits can also have a pair of babies every month after two months. That is, they were born in January, and can have been born continuously since March. If there is no death, how many rabbits after one year?
# Include
# Include
Int Fibonacci (int n)
{
Int r1, r2;
If (n = 1 | n = 2)
{
Return 1;
}
Else
{
R1 = maid (n-1 );
R2 = maid (n-2 );
Return r1 + r2;
}
}
Int main ()
{
Int r, sum;
Printf ("recursive algorithm for rabbit litter: \ n ");
Printf ("Enter the deadline :");
Scanf_s ("% d", & r );
Sum = maid (r );
Printf ("after % d months, a total of % d pairs of rabbits are allowed, total number of rabbits % d only. \ n", r, sum, 2 * sum );
System ("pause ");
Return 0;
}