题解 | #Fibonacci数列#
Fibonacci数列
https://www.nowcoder.com/practice/18ecd0ecf5ef4fe9ba3f17f8d00d2d66
#include <stdio.h> int main() { int arr[40]={1,2}; int i=2; int a=0; int num=0; scanf("%d",&num); while(a<10000000) { arr[i]=arr[i-2]+arr[i-1]; a=arr[i]; i++; } int delta=0; for(int i=0;i<34;i++){ if(num<arr[i]) { int x=arr[i]-num; int y=num-arr[i-1]; delta=x<y?x:y; break; } } printf("%d\n",delta); return 0; }