#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
int Fib(n)
{
int a = 1;
int b = 1;
int c = 1;
if (n <= 2)
{
return 1;
}
else
{
while (n > 2)
{
c = a + b;
a = b;
b = c;
n--;
}
return c;
}
}
int main()
{
int n = 0;
scanf("%d", &n);
int ret = Fib(n);
printf("%d", ret);
return 0;
}
【C语言】每日一代码:计算斐波那契数(迭代法)
最新推荐文章于 2024-06-14 10:22:04 发布