Update 斐波那契数列.cpp

master
p5tblxgmk 3 years ago
parent ed9ccfaf28
commit a552ea00fb

@ -1,17 +1,18 @@
#include<stdio.h>
long Fib(int n)
{
if(n == 0)
return 0;
if(n == 1)
if(n == 1||n == 2)//判断前两项
return 1;
else
return Fib(n - 1)+Fib(n - 2);
return Fib(n - 1)+Fib(n - 2);//递归
}
int main()
{
int n=0;
int n,i;
scanf("%d",&n);
printf("%d\n",Fib(n));
return 0;
for(i=1;i<=n;i++)
{
printf("%d ",Fib(i));//输出前数列n项
}
return 0;
}
Loading…
Cancel
Save