#include<stdio.h>
int f(int n)
{
if(n==1||n==2)return 1;
else return f(n-2)+f(n-1);
}
int main()
{
int i=0,n=0,sum=0;
printf("请输入项数n:\n");
scanf("%d",&n);
for(i=1;i<=n;i++)
{
printf("f(%d)=%d\n",i,f(i));
sum+=f(i);
}
printf("sum=%d\n",sum);
return 0;
}
```#include<stdio.h>
#define max 30
int main()
{
int i,fa[max+1]={0,1,1};
for(i=3;i<=max;i++)fa[i]=fa[i-1]+fa[i-2];
for(i=1;i<=max;i++)printf("fa[%d]=%d\n",i,fa[i]);
return 0;
}
![在这里插入图片描述](https://img-blog.csdnimg.cn/20200608210142775.png)