c语言 计算程序运行时间

c语言 计算程序运行时间,第1张

#include <stdio.h>

#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)

}

}


欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/yw/12200354.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-21
下一篇 2023-05-21

发表评论

登录后才能评论

评论列表(0条)

保存