猜数游戏,不猜对就不退出

/*猜数游戏(其二:重复到猜对为止——利用do语句)*/

#include <stdio.h>

int main(void)
{
    int no;            /* 读取的值 */
    int ans = 7;    /* 目标数字 */

    printf("请猜一个0~9的整数。

");

    do {
        printf("是多少呢:");
        scanf("%d", &no);

        if (no > ans)
            printf("a再小一点。
");
        else if (no < ans)
            printf("a再大一点。
");
    } while (no != ans);                        /* 重复到猜对为止 */

    printf("回答正确。
");

    return 0;
}

输出

请猜一个0~9的整数。

是多少呢:9
再小一点。
是多少呢:7
回答正确。
原文地址:https://www.cnblogs.com/sea-stream/p/11037432.html