C # Bunny Problem

Source: Internet
Author: User

for (int j = 0; J <, J + +)
{
Rabbit problem; Enter the number of months, output into rabbits, bunnies, young rabbits, and the total logarithm of rabbits
int x=0, y=0, z=1,t=1;//x,y,z are the logarithm of rabbits, rabbits and young rabbits respectively; t is the total logarithm
Console.WriteLine ("Please enter the number of months:");
int m = Convert.ToInt32 (Console.ReadLine ());
for (int i = 0; i < m; i++)
{
if (i>0)
{
x = x + y;//this month into rabbit = last month's Rabbit + last month's Bunny
y = z;//Rabbit of the month = last month's Baby Bunny
z = x;//this month's baby rabbit = this month's rabbit
}

}
t = x+y+z;//Total rabbit logarithm
Console.WriteLine (m+ "Months later, a total of" +t+ "to rabbits;);
Console.WriteLine (x + "pairs into rabbits;");
Console.WriteLine (y + "pair of bunnies;");
Console.WriteLine (z + "pairs of young rabbits;");

Console.readkey ();

}

C # Bunny Problem

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.