C++ optimized fibonacci algorithm
作者:互联网
void Util::fib53(int *arr, int num, int &result) { arr[0]=0; arr[1]=1; for(int i=2;i<=num;i++) { arr[i]=arr[i-2]+arr[i-1]; } for(int i=0;i<=num;i++) { cout<<i<<","<<arr[i]<<"\t\t"; } cout<<endl<<endl; result=arr[num]; }
void fib34(int len)
{
Util ul;
int result;
int *arr = new int[len];
ul.fib53(arr, len, std::ref(result));
cout << "Len=" << len << ",result=" << result << endl;
}
g++ -g -std=c++2a -I. *.cpp ./Model/*.cpp -o h1 -luuid -lpthread
标签:arr,algorithm,int,void,len,Util,optimized,fibonacci,result 来源: https://www.cnblogs.com/Fred1987/p/16027816.html