例子
#include<stdio.h>
#include<time.h>
clock_t start,stop;
double duration;
void MyFuction(int a);
int main()
{
int a;
scanf("%d",&a);
start=clock();//开始计时
MyFuction(a);//需要测试的功能函数
stop=clock(); //停止计时
duration=((double)(stop-start))/CLK_TCK; //计算运行时间
printf("%f%s",duration,"s");//输出运行 MyFuction 所用的时间
return 0;
}
void MyFuction(int a)
/*该例子是一个假递归,没有return,所有程序已经走过的进程都会被挂起,直到程序找到出口,找到出口后会由进及远来执行被挂起的进程(补:原来这叫堆栈,以前讲过,忘了。。。)*/
{
if(a>0)
{
MyFuction(a-1);
printf("%d\n",a);
}
}
要点
测试函数的实现和MyFuction函数中递归的深刻理解
退出登录?