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;

}

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

相关推荐
0xDevNull2 小时前
Java反射机制深度解析:从原理到实战
java·开发语言·后端
小小亮012 小时前
Next.js基础
开发语言·前端·javascript
ALex_zry2 小时前
C++网络编程心跳机制与连接保活:长连接稳定性保障
开发语言·网络·c++
Amumu121383 小时前
Js:正则表达式(二)
开发语言·javascript·正则表达式
米粒13 小时前
力扣算法刷题 Day 27
算法·leetcode·职场和发展
Sgf2273 小时前
ES8(ES2017)新特性完整指南
开发语言·javascript·ecmascript
好大哥呀3 小时前
C++ Web 编程
开发语言·前端·c++
ID_180079054733 小时前
小红书笔记评论 API,Python 调用示例与完整 JSON 返回参考
java·开发语言
Fuxiao___4 小时前
C 语言核心知识点讲义(循环 + 函数篇)
算法·c#
漫随流水4 小时前
c++编程:反转字符串(leetcode344)
数据结构·c++·算法