有一对幼兔,幼兔1个月后长成小兔,小兔1个月后长成成兔并生下一对幼兔,问几年后有多少对兔子,幼兔、小兔、成兔对数分别是多少。


  Console.WriteLine("请输入经过了几个年:");

  int n = Convert.ToInt32(Console.ReadLine());

   int syt = 1, byt = 0;

   int sxt = 0, bxt = 0;

   int sdt = 0, bdt = 0;

   for (int i = 1; i <= n; i++)

   {

   byt = sdt + sxt;

   bxt = syt;

   bdt = sdt + sxt;

   syt = byt; sxt = bxt; sdt = bdt;

   }

  Console.WriteLine("经过" + n + "个年后:");

  Console.WriteLine("幼兔为:" + byt + "");

  Console.WriteLine("小兔为:" + bxt + "");

  Console.WriteLine("大兔为:" + bdt + "");

  int sum = byt + bxt + bdt;

   Console.WriteLine("兔子总共有:" + sum + "");

   Console.WriteLine("兔子总共有:{0}对,小兔子有{1}对", sum, bxt);

原文地址:https://www.cnblogs.com/zc290987034/p/5870581.html