static void Main(string[] args)
{
while (true)
{
Console.Write("请输入第几个月份:");
int s = Convert.ToInt32(Console.ReadLine());
int a = 1;//开始幼兔对数
int b = 0;//开始小兔对数
int c = 0;//开始成兔对数
int m = 1;//开始总兔对数
for (int i = 1; i <=s; i++)
{
if (i==1)
{
a = 1;
b = 0;
c = 0;
}
else if(i>1)
{
c = c + b;//本月成=上月成+上月小
b = a;//本月小=上月幼
a = c;//本月幼=本月成
}
m = a + b + c;
Console.WriteLine(i + "个月后的成兔是:" + c);
Console.WriteLine(i + "个月后的小兔是:" + b);
Console.WriteLine(i + "个月后的幼兔是:" + a);
Console.WriteLine(i + "个月后的成兔是:" + m);
Thread.Sleep(1000);
}
}
}
原文:http://www.cnblogs.com/dlexia/p/4381285.html