You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Function/斐波那契数列.cpp

18 lines
274 B

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