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;

}

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

相关推荐
沈阳信息学奥赛培训7 分钟前
#undef 指令 (C/C++)
c语言·开发语言·c++
2401_873204659 分钟前
分布式系统安全通信
开发语言·c++·算法
Dxy12393102161 小时前
JS发送请求的方法详解
开发语言·javascript·ecmascript
sw1213891 小时前
C++中的代理模式实战
开发语言·c++·算法
難釋懷1 小时前
Lua语法入门-条件控制、函数
开发语言·junit·lua
桌面运维家2 小时前
Win10打印机共享故障排查:权限与网络配置详解
开发语言·网络·php
ballball~~2 小时前
ISP-CCM(Color Correction Matrix)
图像处理·数码相机·算法
Sunshine for you2 小时前
实时操作系统中的C++
开发语言·c++·算法
史蒂芬_丁2 小时前
C++深度拷贝例子
java·开发语言·c++
中科院提名者3 小时前
BPE 算法的硬核拆解——理解词表(Vocabulary)是如何从零训练出来的,以及字符串是如何被切碎的
算法