标签:== 数列 return int ret style 习题 turn ||
其实是一个斐波拉契数列问题
1 #include<stdio.h> 2 int rabbit(int month); 3 4 int main() 5 { 6 int n; 7 scanf_s("%d", &n); 8 int month=0; 9 10 while (rabbit(month)<n) 11 { 12 month++; 13 } 14 15 printf("%d\n", month); 16 17 return 0; 18 } 19 int rabbit(int month) 20 { 21 int a, b, c, i; 22 a = b = 1; 23 if (month == 0) 24 { 25 return 0; 26 } 27 else 28 { 29 if (month == 1 || month == 2) 30 { 31 return 1; 32 } 33 else 34 { 35 for (i = 3; i <= month; i++) 36 { 37 c = a; 38 a = b; 39 b = a + c; 40 } 41 return b; 42 } 43 } 44 }
标签:== 数列 return int ret style 习题 turn ||
原文地址:https://www.cnblogs.com/2018jason/p/10907006.html