21xrx.com
2024-05-09 06:50:56 Thursday
登录
文章检索 我的文章 写文章
生成斐波那契数列的 C++ 程序
2021-07-08 15:19:10 深夜i     --     --
+ +

斐波那契数列的 C++ 程序。

C++编程代码

#include<iostream>


using namespace std;

main()
{
   int n, c, first = 0, second = 1, next;

   cout << "Enter the number of terms of Fibonacci series you want" << endl;
   cin >> n;

   cout << "First " << n << " terms of Fibonacci series are :- " << endl;

   for ( c = 0 ; c < n ; c++ )
   {
      if ( c <= 1 )
         next = c;
      else
      {
         next = first + second;
         first = second;
         second = next;
      }
      cout << next << endl;
   }

   return 0;
}

 

  
  

评论区

{{item['qq_nickname']}}
()
回复
回复