【题目描述】
菲波那契数列是指这样的数列: 数列的第一个和第二个数都为1,接下来每个数都等于前面2个数之和。给出一个正整数k,要求菲波那契数列中第k个数是多少。
【输入】
输入一行,包含一个正整数k。(1 ≤ k ≤ 46)
【输出】
输出一行,包含一个正整数,表示菲波那契数列中第k个数的大小。
【输入样例】
19
【输出样例】
4181
- #include<iostream>
- #include<cstdio>
- using namespace std;
- int main()
- {
- int k,f,f1=1,f2=1;
- scanf("%d",&k);
- f=1;
- for(int i=3;i<=k;i++)
- {
- f=f1+f2;
- f1=f2;
- f2=f;
- }
- printf("%d",f);
- return 0;
- }
UP主创作不易,点个赞评论支持一下吧~
本文来自投稿,不代表本站立场,如若转载,请注明出处:
cialis with priligy The Center for Medicare and Medicaid Services sponsored Medicare program covers hospital services, physician services, some drug therapy, and other medical services for more than 97 of persons aged 65 years and older