永远把艰辛的付出看作是生命的必要;
即使没有收获的指望,也心平气静地继续耕种!
94/100 C Programs(猜数)
上一篇 /
下一篇 2008-04-08 00:20:11
/ 个人分类:C
/*【程序94】
LUPA开源社区9\4?_-mN
X,C3O
x题目:时间函数举例4,一个猜数游戏,判断一个人反应快慢。
LUPA开源社区lV.@c k/w&^1.程序分析:
-o\*~ AzSF02.程序源代码:*/
LUPA开源社区w&D;k)Z}@0mp
`X#include "time.h"
LUPA开源社区wv2k0f-_2Dl9C#include "stdlib.h"
LUPA开源社区Q WU
[]N#include "stdio.h"
2P
e_"}nz_uehz0void main(void)
$TLN+gV0{
C$D}7x:M9l`q0 char c;
LUPA开源社区"G.u1oG&f)r7lJ clock_t start, end;
#]8O(e'g|k0 time_t a, b;
LUPA开源社区1_]K P"ZC/lv Kvj double var;
W vGX'h;Vq;yV{0 int i, guess;
%lxKFV b
g0 srand(time(NULL));
_2H6Wz c
R6J0 printf("do you want to play it.('y' or 'n') \n");
)H z5Cu }W8oW7uYP0loop:
LUPA开源社区,T pU"N!s4U4Y
Yb while((c = getchar()) == 'y')
LUPA开源社区C)_3[ {(Cn"f_V {
LUPA开源社区.g2g;u#Y*@8ia i = rand() % 100;
6Fy)g^/n0 printf("\nplease input number you guess:\n");
LUPA开源社区:eoc5? B;},s start = clock();
^t;K-E'g:l'pZ0 a = time(NULL);
"c UJ0c3o9i0 scanf("%d", &guess);
2_4_'c{Aw3I)c(fo0 while(guess != i)
LUPA开源社区*gp0N!lz,Tdl {
LUPA开源社区0~6TvE1Hp+g"E(|:F if(guess > i)
6it:]1UT0 {
5tu+o(]6ZwL0 printf("please input a little smaller.\n");
LUPA开源社区d7s[` w:X:uE3V(W)q scanf("%d", &guess);
R#Z2h'Ew@0 }
)s!V_;{5\0HX-l!WE0 else
LUPA开源社区c:?$TR!a5Z {
:v'QVz$l5l7D?0 printf("please input a little bigger.\n");
LUPA开源社区9e7n
F2e'vFt$@ scanf("%d", &guess);
`3IUQ
r,I U Y"y:\0 }
ir%~gmP#Se0 }
LUPA开源社区(J
R7DxuC+M.n8GL([T end = clock();
LUPA开源社区
S{C)f(Gv b = time(NULL);
vSV-\U
_rB0 printf("\1: It took you %6.3f seconds\n", var = (double)(end - start) / 18.2);
NhQ Kya#G
I0 printf("\1: it took you %6.3f seconds\n\n", difftime(b, a));
-v@D;aa@4y0 if(var < 15)
LUPA开源社区&~SY]5SSh{!{ printf("\1\1 You are very clever! \1\1\n\n");
ZpZv9R
VZ&Y0 else if(var < 25)
#iq/Q5Ae0 printf("\1\1 you are normal! \1\1\n\n");
LUPA开源社区%eg!`bP$k$d4e)n Z else
LUPA开源社区&G%SY1V(c4e~ printf("\1\1 you are stupid! \1\1\n\n");
(d`uH rw sdo0 printf("\1\1 Congradulations \1\1\n\n");
LUPA开源社区c;@5IA;^ ZS+B printf("The number you guess is %d", i);
LUPA开源社区9a/TfRf6O d
L }
LUPA开源社区Br0FcI/U1{ printf("\ndo you want to try it again?(\"yy\".or.\"n\")\n");
LUPA开源社区Hui9Jj:f'vr6c LUPA开源社区C$m&N#h.yrg)S.b qV9i if((c = getchar()) == 'y')
LUPA开源社区*O%c;f+}6p goto loop;
}/]/CW\xVD4T$e0pr0}
p0pO]U7q0
导入论坛
收藏
分享给好友
管理
举报
TAG: