一个猜数游戏,判断一个人反应快慢
2008-11-11 20:50
197 查看
#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;
}
#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;
}
相关文章推荐
- C/ 时间函数举例4,一个猜数游戏,判断一个人反应快慢
- 判断用户是否在线及实现一个账号一个人登陆
- 【练习题】编写一个名为is_palindrome的函数,判断一个人名是否为回文,如‘BOB’是回文
- [置顶] 猜数游戏,在键盘上输入一个数,判断是否猜对(给定的数组和随机产生数组)。
- 【数据结构】单链表—判断一个链表是否形成了环形结构 — 快慢指针
- 一个人并不寂寞,想一个人才寂寞:QQ空间情感日志
- 判断两个IP大小关系及是否在同一个网段中
- 工作:作一个简单的选择判断
- 已知一个数组,每一行都按照从左到右递增的顺序排序, 每一列都按照从上到下递增的顺序排序。请完成一个函数, 输入这样的一个二维数组和一个整数,判断数组中是否含有该整数
- 在一个事件中,判断另外一个事件是否发生,如果发生了进行传值。
- 如何判断一个类是否支持某属性和方法以及如何判断IOS的版本
- 3.【练习题】构造方法与重载 定义一个网络用户类,要处理的信息有用户ID、用户密码、email地址。拓展:判断密码长度
- 100. Same Tree和判断一个树是不是对称的思想一样
- javascript(jquery)中如何判断一个元素在页面中是否存在
- 判断一个数组是否存在三个元素为某一定值
- 判断一个字符串中的字符是否唯一(面试题1)
- 一道遇到的面试题: 怎么判断一个随机数生成程序是真随机
- 写一函数判断一个整数是否是素数。在main函数中调用该函数输出2~100中所有素数。
- 在 Java 的多线程中,如何去判断给定的一个类是否是线程安全的(另外:synchronized 同步是否就一定能保证该类是线程安全的。)
- 怎样知道一个数字是不是2的乘方?怎样判断一个数是不是奇数? Java实现