一对幼兔一个月长成小兔,再过一月长成成兔并生下幼兔,问24个月之后有多少对兔子,成兔每个月都会生下一对幼兔
int a=1,b=0,c=0,sum = 0;//a 幼兔对数,b 小兔对数,c 成兔对数,sum 总对数 for (int i = 1; i <=24; i++) { if (i == 1) { a = 1; b = 0; c = 0; } else { c = b + c; b = a; a = c; } sum = a + b + c; Console.WriteLine(i+"个月后,一共有兔子" + sum + "对,其中幼兔" + a + "对,小兔" + b + "对,成兔" + c + "对!"); Console.ReadLine(); }