C语言的计算耗时问题

C语言的计算耗时问题,第1张

#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/12241690.html

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

发表评论

登录后才能评论

评论列表(0条)

保存