
在一个程序中,一个数字已经被初始化为某个常数。在这里,我们需要要求用户猜测已经在程序中的那个数字。为此,我们需要为每次用户输入数字提供一些线索。
用于猜测数字的逻辑如下所示−
do{
if(num==guess){
flag=0;
} else if(guess<num) {
flag=1;
printf("Your guess is lower than the number</p><p>");
count++;
} else {
flag=1;
printf("Your guess is greater than the number</p><p>");
count++;
} if(flag==1) {
printf("sorry wrong enter! once again try it</p><p>");
scanf("%d",&guess);
}
} while(flag);以下是猜数字游戏的C程序。
本文档主要讲述的是j2me3D游戏开发简单教程; 如今,3D图形几乎是任何一部游戏的关键部分,甚至一些应用程序也通过用3D形式来描述信息而获得了成功。如前文中所述,以立即模式和手工编码建立所有的3D对象的方式进行开发速度很慢且很复杂。应用程序中多边形的所有角点必须在数组中独立编码。在JSR 184中,这称为立即模式。希望本文档会给有需要的朋友带来帮助;感兴趣的朋友可以过来看看
0
实时演示
#include<stdio.h>
main() {
int i,num=64,flag=1,guess,count=0;
printf("guess the number randomly here are some clues later</p><p>");
scanf("%d",&guess);
do {
if(num==guess) {
flag=0;
} else if(guess<num) {
flag=1;
printf("Your guess is lower than the number</p><p>");
count++;
} else {
flag=1;
printf("Your guess is greater than the number</p><p>");
count++;
}
if(flag==1) {
printf("sorry wrong enter! once again try it</p><p>");
scanf("%d",&guess);
}
} while(flag);
printf("Congratulations! You guessed the correct number %d</p><p>",num);
printf("Total number of trails you attempted for guessing is: %d</p><p>",count);
}当上述程序被执行时,它产生以下输出 −
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
以上就是编写一个C程序来进行猜数字游戏的详细内容,更多请关注php中文网其它相关文章!
每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号