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;

}

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

相关推荐
wudl55667 分钟前
JDK 21性能优化详解
java·开发语言·性能优化
wan5555cn26 分钟前
中国启用WPS格式进行国际交流:政策分析与影响评估
数据库·人工智能·笔记·深度学习·算法·wps
AndrewHZ28 分钟前
【图像处理基石】图像形态学处理:从基础运算到工业级应用实践
图像处理·python·opencv·算法·计算机视觉·cv·形态学处理
wjs202429 分钟前
ionic 列表:详解移动端UI设计中的列表组件
开发语言
仰泳的熊猫32 分钟前
LeetCode:1905. 统计子岛屿
数据结构·c++·算法·leetcode
Lear37 分钟前
【链表】LeetCode 206.反转链表
算法
Lear40 分钟前
【链表】LeetCode 24.两两交换链表中的节点
算法
xiaoxiangwendao1 小时前
[26] 删除排序数组中的重复项
算法
洲覆1 小时前
SQL 性能优化:出现 sql 比较慢怎么办?
开发语言·数据库·sql·mysql
熊小猿1 小时前
如何在 Spring Boot 项目中使用 @Slf4j 注解结合 Logback 进行系统日志管理
java·开发语言·spring boot