zoukankan      html  css  js  c++  java
  • 时间函数举例4:猜数字游戏。

    #include <stdio.h>
    #include <conio.h>
    #include <stdlib.h>
    #include <time.h>
    int main()
    {   /*时间函数4:猜数字游戏*/
        int i,guess;
        char c;
        double var;
        time_t a,b;
        clock_t start,end;
        srand(time(NULL));
        printf("\ndo you want to play a game.('y'or'n')\n");
        loop:
        while((c=getchar())=='y')
        {
            i=rand()%100;
            printf("please input the number you guess.\n");
            scanf("%d",&guess);
            start=clock();
            a=time(NULL);
            while(guess!=i)
            {
                if (i>guess)
                {
                    printf("\nplease input a little bigger.\n");
                    scanf("%d",&guess);
                }
                else
                {
                    printf("\nplease input a little smaller.\n");
                    scanf("%d",&guess);
                }
            }
            end=clock();
            b=time(NULL);      //时间的单位是浮点型的
            printf("\1\1:you took the time is %6.3fseconds\n",var=(double)(end-start)/18.2);
            printf("\1\1:you took the time is %6.3fseconds\n",difftime(b,a));
            if(var<15)
                printf("\1\1:you are clever.\n");
                else if(var<25)
                    printf("\1\1:you are normal.\n");
                    else
                        printf("\1\1:you are stupid.\n");
            printf("\1\1:congratulations to you.\1\1\n");
            printf("\1\1:you guess the number is %d\1\1\n",i);
         }
         printf("do you want to play it again.(\"y\"or\"n\")\n");
         if ((c=getch())=='y')  //getch  getchar是不同的
         goto loop;
         return 0;
    }

  • 相关阅读:
    pl/sql 编程!
    oracle中的常用函数、字符串函数、数值类型函数、日期函数,聚合函数。
    oracle 相关查询和非相关查询,oracle 去除重复数据,以及oracle的分页查询!
    初识 oracle!
    分页查询。
    利用ajax技术 实现用户注册。
    quartz CronExpression
    SQL 面试题
    什么是HTTP协议?常用的状态码有哪些?
    聚集索引与非聚集索引
  • 原文地址:https://www.cnblogs.com/wangjingyuwhy/p/2943370.html
Copyright © 2011-2022 走看看