#include <time.h>
#define N 10000 /*这个数字可以自己改,如果时间太长结果不出来你就改小点*/
void f()
{
int i, j, k
for ( i = 0i <N++i )
for ( j = 0j <N++j )
for ( k = 0k <N++k )
}
int main()
{
clock_t begin, duration
begin = clock()
f()
duration = clock() - begin
printf( "函数f()的运行时间大约为:%dms\n", duration*1000/CLOCKS_PER_SEC )
}
#include "stdio.h"#include <time.h>
void hannota(int n,char ta1,char ta2,char ta3)
void main()
{
int n
clock_t begin, duration
printf("input the number of diskes:")
scanf("%d",&n)
begin = clock()
hannota(n,'1','2','3')
duration = clock() - begin
printf( "用时约: %d毫秒", duration*1000 / CLOCKS_PER_SEC )
printf("\n")
}
void hannota(int n,char ta1,char ta2,char ta3)
{
if(n==1)
printf("%c--->%c",ta1 ,ta2)
else
{
hannota(n-1,ta1,ta3,ta2)
printf("%c---->%c",ta1,ta2)
hannota(n-1,ta3,ta2,ta1)
}
}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)