2020-06-04(C语言) 斐波那契数列

//斐波那契数列,斐波那契数列指的是这样一个数列 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233,377,610,987,1597,2584,4181,6765,10946,17711,28657,46368........这个数列从第3项开始,每一项都等于前两项之和。

include

int main()
{
int t1, t2, sum, n, i;
t1 = 0;
t2 = 1;
printf("输入几项:");
scanf("%d", &n);
for (i = 0; i <= n; i++)
{
printf("%d,", t1);
sum = t1 + t2;
t1 = t2;
t2 = sum;
}
printf("\n");
return 0;
}
//运行结果:


WX20200604-173617.png

你可能感兴趣的:(2020-06-04(C语言) 斐波那契数列)