#include<stdio.h>标签:Fib,return,递归,int,斐波,num,fib,printf,那契 From: https://blog.51cto.com/u_13606048/6095970
int Fib(int x) {
if (x <= 2) {
return 1;
}
else {
return Fib(x - 1)+Fib(x-2);
}
}
//效率很低
int fib(int x) {
int i = 1;
int a = 1;
int b = 1;
while (x > 2) {
i = a + b;
b = a;
a = i;
x--;
}
return i;
}
//效率很高
int main() {
int num = 0;
printf("请输入想要查询的第几位数字:");
scanf_s("%d", &num);
printf("%d\n", Fib(num));
printf("%d", fib(num));
return 0;
}