Fibonacci Recursive algorithm

Source: Internet
Author: User

/***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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: [email protected] and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.