程序运行时间问题

[复制链接]
1391|2
 楼主| 秋天落叶 发表于 2012-6-14 16:58 | 显示全部楼层 |阅读模式
[code=C/C++][/code]#include<cmath>
#include<ctime>
#include<iostream>
#include<time.h>
using namespace std;

int fib(int n){
int fib=0;
int i;
int f1=1;
int f2=1;
if(n==1 || n==2)
return 1;
else{
for(i = 3; i <= n; i++){
fib = f1 + f2;
f1 = f2;
f2 = fib;
}
}

return fib;
}
int main(){
int N,result;
clock_t start,end;
cout << "Enter a Number: ";
cin >> N;
start = clock();
result = fib(N);
int duration =(int) (end - start) / CLOCKS_PER_SEC ;
cout << "The fib number is : " << result << endl;
cout << "The program takes "<< duration << endl;
//system("Pause");
return 0;
}
得出的运行时间为-1073,即使换N值也是一样的时间-1073,在linux环境下运行的,用的是putty.
请问怎么改?精确到毫秒的话是不是在CLOCLS_PER_SEC 后面*1000?谢谢
sinadz 发表于 2012-6-14 22:04 | 显示全部楼层
没太看明白,应该用一个时间相关的函数就可以吧
firstblood 发表于 2012-6-18 10:12 | 显示全部楼层
偶也没太明白的啊,顶起了
您需要登录后才可以回帖 登录 | 注册

本版积分规则

个人签名:落叶很美

138

主题

3044

帖子

1

粉丝
快速回复 在线客服 返回列表 返回顶部