首页  

C语言猜数字     所属分类 c 浏览量 134
C语言猜数字
gcc guess.c 
./a.out

gcc -o guess guess.c 
./guess 



#include  <time.h>
#include  <stdlib.h>
#include  <stdio.h>
int main()
{
    int  magic, guess, counter = 0, ret;
    char reply;
    srand(time(NULL));    
    do{
        counter = 0;
        magic = rand() % 100 + 1;
        do{
            printf("Please guess a magic number:");
            ret = scanf("%d", &guess);
            while (ret != 1)
            {
                while (getchar() != '\n');    
                printf("please input a int number 1~100 :");
                ret = scanf("%d", &guess);
            }
            counter++;
            if (guess > magic)
                printf("Wrong!Too big!\n");
            else if (guess < magic)
                printf("Wrong!Too small!\n");
            else
                printf("Right!\n");
        } while (guess!=magic && counter<10);
        printf("counter = %d\n", counter);
        printf("The magic is %d\n",magic);
        printf("Do you want to continue(Y/N or y/n)?");
        scanf(" %c", &reply);   
    }while (reply=='Y' || reply=='y');
    
    return 0;
}




java 猜数字

上一篇     下一篇
Lua 语法 总结

全球ETF行业发展2020年度报告

c语言整数进制

java 猜数字

go猜数字游戏

Rust安装