code4sk/c/sourcecode/朱森森带领的奇妙冒险/2022-2023第二学期单开班第1次月考/求满足条件的斐波那契数.cpp
2023-12-15 22:38:26 +08:00

41 lines
No EOL
846 B
C++
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/* 7-6 求满足条件的斐波那契数
分数 10
作者 陈春晖
单位 浙江大学
斐波那契数亦称之为斐波那契数列指的是这样一个数列1、1、2、3、5、8、13、21、……这个数列从第3项开始每一项都等于前两项之和。求大于输入数的最小斐波那契数。
输入格式:
在一行输人一个正整数n(n>=10)。
输出格式:
在一行输出大于n的最小斐波那契数。
输入样例:
在这里给出一组输入。例如:
10
输出样例:
在这里给出相应的输出。例如:
13
代码长度限制
16 KB
时间限制
400 ms
内存限制
64 MB */
#include <stdio.h>
int main()
{
int a = 1, b = 1, c, n;
scanf("%d", &n);
for (int i = 1; c <= n; i++)
{
c = a + b;
a = b;
b = c;
}
printf("%d", c);
return 0;
}