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

  • 相关阅读:
    JavaScript操作符instanceof揭秘
    Linux打开txt文件乱码的解决方法
    Working copy locked run svn cleanup not work
    poj 2299 UltraQuickSort 归并排序求解逆序对
    poj 2312 Battle City 优先队列+bfs 或 记忆化广搜
    poj2352 stars 树状数组
    poj 2286 The Rotation Game 迭代加深
    hdu 1800 Flying to the Mars
    poj 3038 Children of the Candy Corn bfs dfs
    hdu 1983 Kaitou Kid The Phantom Thief (2) DFS + BFS
  • 原文地址:https://www.cnblogs.com/wangjingyuwhy/p/2943370.html
Copyright © 2011-2022 走看看