作者ck940560 (小弼)
看板NTUBIME101HW
标题Re: [C++] 费事数列-loop
时间Thu Oct 23 22:17:51 2008
※ 引述《naruto1031 (毛毛)》之铭言:
: #include "stdafx.h"
: #include "iostream"
: using namespace std;
: int _tmain(int argc, _TCHAR* argv[])
: {
: double a = 0, b = 1 ,c;
: cout << a <<endl<< b<<endl ;
: for (int i = 0; i<100 ; i++)
: {
: c = a+b;
: a = b;
: b = c;
: cout << c << endl;
: }
: system("pause");
: return 0;
: }
: 不知道这样有没有比较短
这个程式码有两个小缺点,
如果今天做的是cin一个n,要求显示出n个费事数列,
那麽当n=1时还是会输出两个数。
所以卷哥他才用了if解决这个问题。
另外就是位数多的值会变科学记号,用fixed就可以解决了。
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 118.166.242.194