编写一个猜数字游戏的 C 程序。
问题
在程序中,一个数字已经被初始化为某个常量。在这里,我们必须让用户猜测程序中已经存在的那个数字。为此,我们需要为用户每次输入号码提供一些线索。
解决方案
用于猜测数字的逻辑如下-
do{
if(num==guess){
flag=0;
} else if(guess示例
以下是猜数字游戏的C程序。
#include
main() {
int i,num=64,flag=1,guess,count=0;
printf("guess the number randomly here are some clues later\n");
scanf("%d",&guess);
do {
if(num==guess) {
flag=0;
} else if(guess输出结果执行上述程序时,它会产生以下输出-
guess the number randomly here are some clues later
45
Your guess is lower than the number
sorry wrong enter! once again try it
60
Your guess is lower than the number
sorry wrong enter! once again try it
70
Your guess is greater than the number
sorry wrong enter! once again try it
65
Your guess is greater than the number
sorry wrong enter! once again try it
62
Your guess is lower than the number
sorry wrong enter! once again try it
64
Congratulations! You guessed the correct number 64
Total number of trails you attempted for guessing is: 5
热门推荐
10 学生开学季祝福语简短
11 祝福语大全简短6个
12 写给情侣祝福语 浪漫简短
13 职场离职文案祝福语简短
14 师生聚餐的祝福语简短
15 情人表白祝福语简短大气
16 姐妹结婚快乐祝福语简短
17 给长辈祝福语简短大全
18 祝美术老师祝福语简短