标签:ret col 数列 ios space std names while namespace
一:解题思路
这道题目的本质就是求斐波那契数列的第n项。
二:完整代码示例 (C++版和Java版)
C++代码:
#include <iostream> using namespace std; int main() { int months = 0; while (cin >> months) { int f1 = 1; int f2 = 1; for (int i = 2; i < months; i++) { int f3 = f1 + f2; f1 = f2; f2 = f3; } cout << f2 << endl; } return 0; }
标签:ret col 数列 ios space std names while namespace
原文地址:https://www.cnblogs.com/repinkply/p/13441549.html