Introduce 包含递归

个人学习笔记

递归是指函数调用自己本身。想知道什么是递归,首先你得知道什么是递归。
 
下面是一个显示当n为不同值时运行时间的小程序
#include<iostream> #include<ctime> using namespace std;

clock_t start = clock();  int f(long int num)
{ if(num == 0)
    {
        cout<<"Using "<<(clock())<<"seconds
" ; return 0;
    }
    else f(num/2);
} int main()
{
    cout<<"The start time is: "<<start<<endl; long int n;
    cout<<"Please input a num:
";
    cin>>n;
    f(n);
}


 

原文地址:https://www.cnblogs.com/kbe317/p/4143092.html