int fib(int n,int a,int b){
if (n==2){
return a+b;
}
return fib(n-1,b,a+b);
}
int main() {
time_t begin,end;
begin = clock();
fib(10000,0,1);
end = clock();
printf("%f",difftime(end,begin));
}
int main() {
time_t begin,end;
time(&begin);
fib(10000,0,1);
time(&end);
printf("%f",(double)(end-begin)/CLOCKS_PER_SEC);
}
1)First question
Why does my first main give prints me a time 288.000000
,I'm assuming this is 288 milliseconds but in the documentation it is supposed to give me the result in seconds.I am on Mac by the way.
2)Second Question
Why does the second main.
Why does this print me the output time being 0.000000
.
I understand that time() give me a time_t structure that i put inside begin
and end
time_t
structs and then i find the difference in seconds,doesn't seem to work.