永远把艰辛的付出看作是生命的必要; 即使没有收获的指望,也心平气静地继续耕种!

94/100 C Programs(猜数)

上一篇 / 下一篇  2008-04-08 00:20:11 / 个人分类:C  

/*【程序94】LUPA开源社区9\4? _-mN X,C3O x
题目:时间函数举例4,一个猜数游戏,判断一个人反应快慢。LUPA开源社区lV.@ck/w&^
1.程序分析:
-o \*~ AzSF02.程序源代码:*/LUPA开源社区w&D;k)Z }@0mp `X
#include "time.h"LUPA开源社区w v2k0f-_2Dl9C
#include "stdlib.h"LUPA开源社区QWU [ ]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");
)Hz5Cu }W8oW7uYP0loop:LUPA开源社区,T p U"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:]1U T0            {
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            elseLUPA开源社区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
        elseLUPA开源社区&G%S Y1V(c4e~
            printf("\1\1 you are stupid! \1\1\n\n");
(d ` uH rwsdo0        printf("\1\1 Congradulations \1\1\n\n");LUPA开源社区c;@5IA;^ ZS+B
        printf("The number you guess is %d", i);LUPA开源社区9a/TfR f6O 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:

 

评分:0

我来说两句

显示全部

:loveliness: :handshake :victory: :funk: :time: :kiss: :call: :hug: :lol :'( :Q :L ;P :$ :P :o :@ :D :( :)

日历

« 2008-11-23  
      1
2345678
9101112131415
16171819202122
23242526272829
30      

数据统计

  • 访问量: 2841
  • 日志数: 43
  • 图片数: 1
  • 文件数: 4
  • 建立时间: 2007-11-07
  • 更新时间: 2008-08-11

RSS订阅

Open Toolbar