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;

}

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

相关推荐
飛67914 小时前
从 0 到 1 掌握 Flutter 状态管理:Provider 实战与原理剖析
开发语言·javascript·ecmascript
Data_agent14 小时前
学术爬虫实战:构建知网论文关键词共现网络的技术指南
python·算法
龚礼鹏14 小时前
Android应用程序 c/c++ 崩溃排查流程
c语言·开发语言·c++
Filotimo_15 小时前
在java开发中,什么是JSON格式
开发语言·json
立志成为大牛的小牛15 小时前
数据结构——五十五、散列查找的性能分析(线性探测法)(王道408)
数据结构·程序人生·考研·算法
咕噜签名-铁蛋15 小时前
云服务器远程连接失败?
开发语言·php
~无忧花开~15 小时前
Vue二级弹窗关闭错误解决指南
开发语言·前端·javascript·vue.js
老华带你飞15 小时前
在线教育|基于springboot + vue在线教育系统(源码+数据库+文档)
java·开发语言·数据库·vue.js·spring boot·后端
神也佑我橙橙16 小时前
Thrift 简单介绍
算法
simon_skywalker16 小时前
线性代数及其应用习题答案(中文版)第二章 矩阵代数 2.1 矩阵运算(2)
线性代数·算法·矩阵