斐波那契数列 题解:C
#include <stdio.h>
int main()
{
int n;
while(scanf("%d",&n) != EOF)
{
if(n == 0 || n == 1) printf("1\n");
else if(n == 2) printf("2\n");
else
{
long long i,a = 1,b = 1,c = 2,t;
for(i = 2; i < n; i++)
{
t = a+b+c;
a = b;
b = c;
c = t;
}
printf("%lld\n",c);
}
}
return 0;
}
登录后发布评论
暂无评论,来抢沙发