看板 NTUBIME101HW 關於我們 聯絡資訊
※ 引述《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