博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

Fibonacci_array

Posted on 2019-01-16 11:12  惊鸿BoltLi  阅读(127)  评论(0编辑  收藏  举报
重新开始学习C&C++   Courage is resistance to fear, mastery of fear, not abscence of fear  
 1 //斐波那契数列 Fibonacci数列
 2 #include <iostream>
 3 #include <iomanip>
 4 using namespace std;
 5 int main()
 6 {
 7 long f1, f2;
 8 int i;
 9 f1 = f2 = 1;
10 for (i=1;i<=20;i++)
11 {
12 cout << setw(12) << f1 << setw(12) << f2;
13 if (i % 2 == 0)cout << endl; //每四个数换行
14 f1 = f1 + f2;    //第三个数
15 f2 = f2 + f1;    //第四个数
16 }
17 return 0;
18 }
View Code