• 时间函数举例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;
    }

  • 相关阅读:
    向存储过程中传入列表参数
    TRUNCATE TABLE (Transact-SQL)
    Program.cs
    联想G40-30 安装win10系统
    完美解决github访问速度慢[转]
    关于Visual studio 2017安装方法的若干问题
    [转载] 中国象棋软件-引擎实现(七)测试程序
    [转载] 中国象棋软件-引擎实现(六)局面评估
    [转载] 中国象棋软件-引擎实现(五)历史启发及着法排序
    [转载] 中国象棋软件-引擎实现(四)搜索算法
  • 原文地址:https://www.cnblogs.com/wangjingyuwhy/p/2943370.html
Copyright © 2020-2023  润新知