Question 19: classical question: a rabbit has been born every month since 3rd months after birth, and a rabbit has been born every month after the third month.

Source: Internet
Author: User

/*************************************** ************************
* *** Auther: liuyongahui
* ***** Date:
* ** Language: C
**************************************** ***********************/
/*
Question 19: classical question: there is a rabbit, from birth
Every month, a rabbit was born every three months, and every day after the third month
A rabbit was born every month. If the Rabbit does not die, how many rabbits are there every month?
*/

# Include <stdio. h>

Int f (int n); // statement of the original function

Int main ()
{
Int month;
Int I;
Int sum = 0;

Printf ("Enter the number of months you want :");
Scanf ("% d", & month );

For (I = 1; I <= month; I ++)
{
Sum + = f (I );
}

Printf ("month % d, total number of rabbits % d only \ n", month, sum );

Return;


}


// Function Definition
Int f (int n)
{
If (n = 1 | n = 2)
{
Return 1;
}
Else
{
Return f (n-2) + f (n-1 );
}
}

 

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: info-contact@alibabacloud.com 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.