猜数字游戏

//设计猜数字小游戏,只能猜七次。

#include<stdio.h>

#include<stdlib.h>

#include<time.h>

int main()

{

    srand(time(0));

    int key=rand()%100;

    int n=7,x;

    int start=1,end=100;

    while(n--)

    {

        scanf("%d",&x);

        x=(start+end)/2;

        printf("Current range is [%d,%d]\n",start,end);

        if(x==key)

        {

            printf("congratulation!\n");

            break;

        }

        else if(x<key)

        {

            start=x+1;

            printf("too samll~\n");

        }

        else { end=x-1; printf("too big~");}

    }

    return 0;

}

posted @ 2017-08-16 21:30  我大概是只废喵  阅读(81)  评论(0编辑  收藏  举报