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;
    }

  • 相关阅读:
    PHP IIS SPY
    Java 教程整理:基础、项目全都有
    14门Linux课程,打通你Linux的任督二脉!
    给缺少Python项目实战经验的人
    Spark 简介与安装部署
    仿OpenStack开发云计算管理软件”--熟悉开发环境
    如何利用《C++ Primer》学习C++?
    J2SE核心开发实战(二)——字符串与包装类
    J2SE核心开发实战(一)——认识J2SE
    pygame开发PC端微信打飞机游戏
  • 原文地址:https://www.cnblogs.com/wangjingyuwhy/p/2943370.html
Copyright © 2011-2022 走看看