/********************************
* 程序名称:斐波那契数列 递归算法
* 作 者:tiaya@
* 开发时间: 年 月 日
*******************************/
#include
#include
#include
using namespace std;
//int fab(int n)
double fab(int n) {
if (n<3) {
return 1;
cout << "n=" << n << endl;
} else {
cout << "n=" << n << endl;
return fab(n-1) + fab(n-2);
}
}
//main() star
int main() {
//code here
clock_t start,finish;
double totaltime;
start=clock();
int n;
cin >> n;
cout << "第" << n <
finish=clock();
totaltime=(double)(finish-start)/CLOCKS_PER_SEC;
cout<
return 0;
}
测试:
输入数据:30
30
输出数据:
n=6
n=5
n=4
n=3
n=3
n=4
n=3
n=5
n=4
n=3
n=3
n=6
n=5
n=4
n=3
n=3
n=4
n=3
第30项是:832040
此程序的运行时间为45.016秒!
--------------------------------
Process exited after 44.44 seconds with return value 0
请按任意键继续. . .