猜数游戏,不猜对就不退出
Posted sea-stream
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了猜数游戏,不猜对就不退出相关的知识,希望对你有一定的参考价值。
/*猜数游戏(其二:重复到猜对为止——利用do语句)*/ #include <stdio.h> int main(void) int no; /* 读取的值 */ int ans = 7; /* 目标数字 */ printf("请猜一个0~9的整数。\n\n"); do printf("是多少呢:"); scanf("%d", &no); if (no > ans) printf("\a再小一点。\n"); else if (no < ans) printf("\a再大一点。\n"); while (no != ans); /* 重复到猜对为止 */ printf("回答正确。\n"); return 0;
输出
请猜一个0~9的整数。 是多少呢:9 再小一点。 是多少呢:7 回答正确。
以上是关于猜数游戏,不猜对就不退出的主要内容,如果未能解决你的问题,请参考以下文章