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\n" ; return 0;
    }
    else f(num/2);
} int main()
{
    cout<<"The start time is: "<<start<<endl; long int n;
    cout<<"Please input a num:\n";
    cin>>n;
    f(n);
}


 

posted @ 2014-12-04 16:04  小痴_r  阅读(162)  评论(0编辑  收藏  举报