C语言经典代码——part 26

【程序93】

题目:时间函数举例3

1.程序分析:

2.程序源代码:

/*calculate time*/

#include "time.h"

#include "stdio.h"

main()

{ clock_t start,end;

int i;

double var;

start=clock();

for(i=0;i<10000;i++)

{ printf("\1\1\1\1\1\1\1\1\1\1\n");}

end=clock();

printf("\1: The different is %6.3f\n",(double)(end-start));

}

==============================================================

【程序94】

题目:时间函数举例4,一个猜数游戏,判断一个人反应快慢。(版主初学时编的)

1.程序分析:

2.程序源代码:

#include "time.h"

#include "stdlib.h"

#include "stdio.h"

main()

{char c;

clock_t start,end;

time_t a,b;

double var;

int i,guess;

srand(time(NULL));

printf("do you want to play it.('y' or 'n') \n");

loop:

while((c=getchar())=='y')

{

i=rand()%100;

printf("\nplease input number you guess:\n");

start=clock();

a=time(NULL);

scanf("%d",&guess);

while(guess!=i)

{if(guess>i)

{printf("please input a little smaller.\n");

scanf("%d",&guess);}

else

{printf("please input a little bigger.\n");

scanf("%d",&guess);}

}

end=clock();

b=time(NULL);

printf("\1: It took you %6.3f seconds\n",var=(double)(end-start)/18.2);

printf("\1: it took you %6.3f seconds\n\n",difftime(b,a));

if(var<15)

printf("\1\1 You are very clever! \1\1\n\n");

else if(var<25)

printf("\1\1 you are normal! \1\1\n\n");

else

printf("\1\1 you are stupid! \1\1\n\n");

printf("\1\1 Congradulations \1\1\n\n");

printf("The number you guess is %d",i);

}

printf("\ndo you want to try it again?(\"yy\".or.\"n\")\n");

if((c=getch())=='y')

goto loop;

}

==============================================================

相关推荐
普if加的帕10 分钟前
java Springboot使用扣子Coze实现实时音频对话智能客服
java·开发语言·人工智能·spring boot·实时音视频·智能客服
2301_8076114939 分钟前
77. 组合
c++·算法·leetcode·深度优先·回溯
安冬的码畜日常1 小时前
【AI 加持下的 Python 编程实战 2_10】DIY 拓展:从扫雷小游戏开发再探问题分解与 AI 代码调试能力(中)
开发语言·前端·人工智能·ai·扫雷游戏·ai辅助编程·辅助编程
朝阳5811 小时前
Rust项目GPG签名配置指南
开发语言·后端·rust
朝阳5811 小时前
Rust实现高性能目录扫描工具ll的技术解析
开发语言·后端·rust
程高兴1 小时前
基于Matlab的车牌识别系统
开发语言·matlab
YuforiaCode1 小时前
第十三届蓝桥杯 2022 C/C++组 修剪灌木
c语言·c++·蓝桥杯
牛马baby2 小时前
Java高频面试之并发编程-07
java·开发语言·面试
CodeWithMe2 小时前
【C++】STL之deque
开发语言·c++
SsummerC2 小时前
【leetcode100】零钱兑换Ⅱ
数据结构·python·算法·leetcode·动态规划