Compute the classic Fibonacci running times quantitatively via the third variable
//Util.h static unsigned long long factorialLoops; long double Fibonacci35(int len); //Util.cpp unsigned long long Util::factorialLoops=0; long double Util::Fibonacci35(int i) { Util::factorialLoops++; if(i==0 || i==1) { return 1; } else { return Fibonacci35(i-1)+Fibonacci35(i-2); } } //main.cpp void recursion16(int i) { Util ul; long double fib = 0; for (int x = 0; x < i; x++) { fib = ul.Fibonacci35(x); cout <<fixed<< "Fib of " << x << " is " << fib <<",fibonacci loops is "<<Util::factorialLoops<<endl; } cout<<endl<<"The recursion loops is "<<Util::factorialLoops<<endl; } int main(int args, char **argv) { recursion16(atoi(argv[1])); return 0; }
Compile and run as below command which will cost more time definitely
./h1 100
The following snapshot can demonstrate everything
When run the 54 it call the classic Fibonacci method more than 730 billion times.
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 分享一个免费、快速、无限量使用的满血 DeepSeek R1 模型,支持深度思考和联网搜索!
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· ollama系列01:轻松3步本地部署deepseek,普通电脑可用
· 25岁的心里话
· 按钮权限的设计及实现
2020-04-19 dynamic intercept and interpret all method calls via implementation IDynamicMetadataObjectProvider
2020-04-19 get caller member name,caller file path,caller line number via attributes
2020-04-19 try catch exception when