C++代码,递归方式。
#include <bits/stdc++.h> using namespace std; int get_total_count(int month) //返回值类型整形 { if (month == 1 || month == 2)//边界条件,及其返回值 return 1; return get_total_count(month - 1) + get_total_count(month - 2);//表达式 } int main() { int mon; while(cin>>mon) //本题有多组数据 { cout<<get_total_count(mon)<<endl; } return 0; }