码迷,mamicode.com
首页 > 其他好文 > 详细

Introduce 包含递归

时间:2014-12-04 17:40:36      阅读:165      评论:0      收藏:0      [点我收藏+]

标签:style   blog   io   ar   color   os   sp   on   div   

个人学习笔记

 

递归是指函数调用自己本身。想知道什么是递归,首先你得知道什么是递归。
 
下面是一个显示当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);
}


 

Introduce 包含递归

标签:style   blog   io   ar   color   os   sp   on   div   

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!