‘壹’ c语言猜数字
#include<stdio.h>
#include <time.h>
#include <stdlib.h>
int zishu;
int min=1,max=100;
void jieshou()
{
printf("请在%d到%d中输入您猜的数:",min,max);
scanf("%d",&zishu);
if(zishu<min||zishu>max)
{
printf("\n对不起,您输入的数不合法,请重新输入!");
scanf("%d",&zishu);
}
}
void main()
{
srand( (unsigned)time( NULL ) );
int suiji=rand()%100+1; //产生随机数
int cishu=0;
jieshou(); //接受用户猜的数
while(cishu!=10)
{
if(zishu>suiji) //判断
{
max=zishu;
jieshou();
}
else if(zishu<suiji)
{
min=zishu;
jieshou();
}
else
{
printf("您真牛逼!!这样也能猜对!!");
break;
}
cishu++;
}
if(cishu==10)
exit(0);
}
‘贰’ 猜数游戏C语言程序设计
这道题不难,只要知道怎样用c语言生成1~100的随机数就很好办了!
附代码如下!
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
intmain()
{
index:
printf("请选择是否进行猜数! 1:是 0:否 ");
intj;
scanf("%d",&j);
if(j==0)
return0;
inti,x=rand()%100+1,input;
for(i=0;i<10;i++)
{
printf("请输入猜想的1至100之间的整数:");
scanf("%d",&input);
if(input==x)
{
printf("猜想正确! 你一共猜想了%d次 ",i+1);
gotoindex;
}
if(input<x)
{
if((i+1)>=10)
{
printf(" 此次猜想失败! ");
gotoindex;
}
else
printf("所猜数过小! 请再猜一次! ");
}
if(input>x)
{
if((i+1)>=10)
{
printf(" 此次猜想失败! ");
gotoindex;
}
else
printf("所猜数过大! 请再猜一次! ");
}
}
}
为了简化,使用了goto语句。
‘叁’ c语言:猜数字游戏代码
#include<stdio.h>
#include<stdlib.h>
#include<time.h>
intmain()
{
intnum,n,i,cnt=0,finish=0;
srand((unsignedint)time(NULL));
num=rand()%100;
printf("请猜数字,0~100之间 ");
do{
scanf("%d",&i);
cnt++;
if(i<0&&i>=100)
{
printf("GameOver ");
finish=1;
}
elseif(i>num)printf("Toobig ");
elseif(i<num)printf("Toosmall ");
else
{
printf("你用了%d次机会猜中!",cnt);
finish=1;
}
}while(!finish);
return0;
}
‘肆’ C语言程序设计 功能:猜数字游戏.系统产生一个0-100之间的随机整数,
count++; (guess==number)||(guess==-1)
‘伍’ C语言编程 猜数游戏
#include<stdio.h>
#include<stdlib.h>裤备
#include<time.h>御纯晌镇锋
int main()
{
int a[10];int i=0,j,k,m=1,N;
printf("Would you like to guess a number ?\nYES=1 NO=0\n");
scanf("%d",&N);
srand(time(NULL));
while(N)
{
m=rand()%10;
i=0;
while(i<=10)
{
printf("Please guess a number\n");
scanf("%d",&k);
if(k>m)
{
printf("TOO HIGH !\n");i++;continue;
}
else if (k<m)
{
printf("TOO LOW!\n");i++;continue;
}
if(k==m)
{
printf("RIGHT!\n");
printf("guess %d times\n",i+1);
break;
}
}
if(i==11)printf("NO CHANCE~!\n");
printf("Would you like to guess again ?\nYES=1 NO=0\n");
scanf("%d",&N);
}
return 0;
}
‘陆’ 用C语言编写一个猜数字游戏的程序(最好能够解释一下)
已经改正,如下:
#include<stdio.h>
#include<stdlib.h>
#include<time.h>
void circle(int i)
{
int n ;
printf("请输入您所猜的数字(0-100) \n");
scanf("%d",&n);
if(i<n)
{
printf("the number is larger,input agine.\n");
circle(i);
}
if(i>n)
{
printf("the number is smaller.input agine \n");
circle(i);
}
if(i==n)//?不是
printf("the number is %d so congratulations!you got it!",i);
}
int main()
{
int flag =1;
printf("This is a small game,what you should do is just guess a intange number.\n");
printf("Now,please guess the number!\n");
srand((unsigned)time(NULL));
while(flag)
{
int i=rand()%100;//?使用 % 而不是 / ,产生的数字在0-100之间,放在循环体内,每次循环都产生一个随机数
circle(i);
printf("\n继续玩请输入 1,退出请输入 0");
scanf("%d",&flag);
}
getchar();
return 0;
}
‘柒’ 用C语言for语句设计一个小游戏
分类: 电脑/网络 >> 程序汪中禅设计 >> 其他编程语言
问题困尘描述:
十万火急~~~~明天要交作业
解析:
我写一个猜数字游戏吧!:
/*猜数字游戏:计算机随培闭机给出一个1~100之间的数,你输入一个数,程序判断是否是程序
选定的那个数字,如果不正确,程序会告诉你大于或者小于这个数的提示,如:程序选择是7,你输入8,则提示大于了,给你猜10次*/
#include <stdio.h>
main()
{int i,guess,number;
number=abs(rand()%100)+1;
printf("猜数字:");
for(i=1;i<=10;i++)
{scanf("%d",&guess);
if (guess==number)
{
printf("正确!\n");
break;}
else
if (guess < number)
printf("小了!\n");
else
printf("大了\n");
}
‘捌’ c语言编程:猜数字游戏
#include <time.h>
#include <stdio.h>
#include <stdlib.h>
#define UI unsigned short int
void game()
{
UI answer;
UI input;
UI lower=1;
UI upper=100;
UI count=0;
srand(time(NULL));
do{answer=rand()%101;}
while(answer==0);
puts("Welcome to the number guessing game!");
do
{
puts("Please enter an integer from 1 to 100 (again):");
scanf("%lu",&input);
getchar();
count=count+1;
if(input==answer){puts("You succeeded!");printf("The number of time(s) you entered is %lu.\n",count);}
else
{
puts("You failed!");
if(input<answer){if(input>lower){lower=input;}puts("The answer is greater than your input.");}
else {if(input<upper){upper=input;}puts("The answer is less than your input.");}
printf("The answer is from %lu to %lu.\n",lower,upper);
}
}
while(input!=answer);
}
#undef UI
int main()
{
game();
system("Pause");
return 0;
}
‘玖’ 编写一个猜数的游戏程序。(数字由机器随机产生,限制为1~100之间的整数,用户输入猜测,程序给出大小提示
static void Main(string[] args)
{
string i = null;
do
{
Console.Write("请输入一个整数(范围为1~100)\n如果要退出,请输入0!否则输入1!");
i = Console.ReadLine();
if (i.Trim().Equals("0"))
{
return;
}
} while (!i.Trim().Equals("1"));
start:
Random ra = new Random();
int rndInt = ra.Next(1, 100);
int input = 0;
do
{
Console.Write("输入你猜的数值:");
i = Console.ReadLine();
if (!int.TryParse(i, out input))
{
continue;
}
if (input > rndInt)
{
Console.Write("猜大了\n\n");
}
else if (input < rndInt)
{
Console.Write("猜小了\n\n");
}
} while (input != rndInt);
Console.Write("恭喜你,猜对了!\n\n");
do
{
Console.Write("若继续猜测输入Y,若退出则输入N!\n请输入:");
i = Console.ReadLine();
if (i.Trim().Equals("n", StringComparison.OrdinalIgnoreCase))
{
return;
}
if (i.Trim().Equals("y", StringComparison.OrdinalIgnoreCase))
{
goto start;
}
} while (!i.Trim().Equals("1"));
}
‘拾’ c语言小游戏:猜数字 随机一个1-100之间的数,根据数据输入进行提示
//小游戏:猜数字 随机一个1-100之间的数,根据数岁答据输入进行提示
#include <stdlib.h>
#include <time.h>
int main(void){
int value=0;
int num=0;
srand((unsigned int) time(NULL));
num=rand()%100+1; //1-100
while(1){
scanf("%d",&value);
if(num>value){
printf("您猜小了\n");
}
else if(num<value){
printf("您乎余慧毁桥猜大了\n");
}
else if(num=value){
printf("恭喜您猜对了\n");
break;
}
}
return 0;
}