统计
  • 文章总数:2821 篇
  • 评论总数:2873 条
  • 分类总数:18 个
  • 最后更新:17小时前
辰语AI

信息学奥赛一本通C++语言-----1071:菲波那契数

本文阅读需要 1 分钟
首页 资讯 正文

【题目描述】
菲波那契数列是指这样的数列: 数列的第一个和第二个数都为1,接下来每个数都等于前面2个数之和。给出一个正整数k,要求菲波那契数列中第k个数是多少。
【输入】
输入一行,包含一个正整数k。(1 ≤ k ≤ 46)
【输出】
输出一行,包含一个正整数,表示菲波那契数列中第k个数的大小。
【输入样例】
19
【输出样例】
4181

  1. #include<iostream>
  2. #include<cstdio>
  3. using namespace std;
  4. int main()
  5. {
  6. int k,f,f1=1,f2=1;
  7. scanf("%d",&k);
  8. f=1;
  9. for(int i=3;i<=k;i++)
  10. {
  11. f=f1+f2;
  12. f1=f2;
  13. f2=f;
  14. }
  15. printf("%d",f);
  16. return 0;
  17. }

UP主创作不易,点个赞评论支持一下吧~

本文来自投稿,不代表本站立场,如若转载,请注明出处:

发表评论

V注册会员 L评论等级
R暂无回复
  1. priligy reçetesiz alınır mi :
    2025-03-10     Win 10 /    Chrome

    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

没有更多评论了
    请配置好页面缩略名选项

热门文章