跪求一道c语言猜数游戏的编程题(详情进来看) 知道的大侠们帮帮忙 全部家产都压上了 谢谢了!!

作者&投稿:仪罚 (若有异议请与网页底部的电邮联系)
一道C语言猜数游戏编程题~

#include "stdio.h"
#include
#include
void Guess(int magic, int guess)
{
static int c = 0;
c++;
if (magic == guess)
{
printf("
你猜对了!
你一共猜了%d次!", c);
exit(0);
}
if (magic < guess)
{
printf("
太大了!
");
}
else
{
printf("
太小了!
");
}
}
int main()
{
int m, n, i;
srand((int)time(0));
n=(rand() % 100) + 1;
//printf("n=%d
",n);
for (i = 0; i < 10; i++) {
printf("请输入你猜测的数:");
scanf("%d", &m);
Guess(n, m);
}

return 0;
}

我感觉你给出的已经够简单的了
还要更简单!!那只有改一点点了
#include
#include
void
main()
{
char
t[20],a[20],b[20],c[20];
gets(a);
gets(b);
gets(c);
if
(strcmp(a,b)>0)

strcpy(t,a);

else

strcpy(t,
b);

if
(strcmp(c,t)>0)

strcpy(t,c);
printf("
其中最大字符串:%s
",
t);
}

//时间函数举例4,一个猜数游戏,判断一个人反应快慢。
#include "time.h"
#include "stdlib.h"
#include "stdio.h"
main()
{char c;
clock_t start,end;
time_t a,b;
double var;
int i,guess;
srand(time(NULL));
printf("do you want to play it.('y' or 'n') \n");

loop:
while((c=getchar())=='y')
{
i=rand()%100;
printf("\nplease input the number you guess:\n");
start=clock();
a=time(NULL);
scanf("%d",&guess);
while(guess!=i)
{if(guess>i)
{printf("please input a little smaller.\n");
scanf("%d",&guess);}
else
{printf("please input a little bigger.\n");
scanf("%d",&guess);}
}
end=clock();
b=time(NULL);
printf("\1: It took you %6.3f seconds clock time!\n",var=(double)(end-start)/1000);//时钟计时单位为1毫秒,那么计时的精度也为“1毫秒”。
printf("\1: it took you %6.3f seconds calculate time!\n\n",difftime(b,a)); //而日历时间,即time_t型的变量的单位是秒。
if(var<20)
printf("\1\1 You are very clever! \1\1\n\n");
else if(var<25)
printf("\1\1 you are normal! \1\1\n\n");
else
printf("\1\1 you are stupid! \1\1\n\n");
printf("\1\1 Congradulations \1\1\n\n");
printf("The number you guess is %d",i);
}
if(c!='n')//前面第一次若输入的是“n”,则不执行下面的语句,程序直接结束!
{
printf("\ndo you want to try it again?(\"y\".or.\"n\")\n"); //这里的“yy”是有讲究的,第一个“y”由下面的if语句里getchar()函数获取,
//第二个“y”由while语句里的getchar()获取,之后进才会入while循环!
//另外,双引号里面还有双引号时,会引起“歧义”,故而在双引号前面加上转义字符“\”,此转义字符输出时不显示。

// getchar(); printf("%c",c);
// if((c=getchar())=='y') 这句省去以后,就可以只输入一个y而继续游戏。否则要输入“yy”才行!
goto loop;
}
}

倒确实是个有意思的程序 我可以现在写个给你 就是不知道到时候你有满意答案了没有
你用什么编译器? VC++6.0?

写好了 你看看行不
#include<iostream.h>
#include<stdlib.h>
#include<time.h>

int main()
{
int rd;
int tm=10;
int in;
srand(time(NULL));
rd=rand()%100+1;
while(tm>0)
{
cin>>in;
if(in==rd)
goto win;
else if(in>rd)
cout<<"输入的数大了!\n";
else
cout<<"输入的数小了!\n";
--tm;
}
cout<<"你输了!";
return 0;
win:
cout<<"你赢了!\n";

}

我以前写过一个猜数字的小程序,不是严格符合你的要求,但是你可以参考...邮箱给我,我发给你!


C语言编程:编写一个猜数的游戏,系统自动产生一个随机数,你来猜,程序给...
int y=-1;System.out.println("已生成0~100的随机整数,请输入您所猜的数:");while(x!=y){ y=sc.nextInt();if(y>x){ System.out.println("输入的数过大");} else if(y<x){ System.out.println("输入的数过小");} } System.out.println("正确!该随机数是"+x);sc.close()...

猜数字游戏c语言编程一到五?
include <stdio.h> include <stdlib.h> include int main() { int key, input;srand(time(NULL));key = rand() % 5 + 1;printf("Guess who am I? (from 1 to 5, 0 for exit)\\n");printf("Your answer: ");while (1) { scanf("%d%*c", &input);if (input == 0) { ...

C语言程序设计猜数字游戏
```c include include include define N 4 \/* 随机生成 N 个数字 *\/ define NUM 8 \/* 玩家有 NUM 次猜测机会 *\/ void detect(char s[]) { int i, j, num;int a, b;char ch[N];for (num = 0; num < NUM; num++) { a = b = 0;printf("第%d次机会:", num + 1);f...

用C语言编写一段猜数字游戏,跟一般的不一样,规则如下
进行判断练习,若猜数是50,猜了40,范围变成40到100,若猜60,范围变成40到60.通过循环来控制。include<stdio.h> int main(void){ int a,low,k,he,d;k=50; \/\/k为答案数 low=1;he=100;scanf("%d",&a);while(a!=k){ if(a<k){ low=a;printf("猜数的范围是:%d到%d\\n",low...

设计一个C语言程序 猜数游戏 规则:电脑随机产生一个1-100的随机数让玩 ...
include <stdio.h>#include <stdlib.h> #includeint main(void){int rst,g;int guesscount;\/\/用随机函数了srand( time(NULL) );printf("猜数游戏,输入-1退出.\\r\\nLet's go !\\r\\n\\r\\n");do{\/\/生成随机数rst = (int)((double) rand() \/(double) RAND_MAX * 100);\/\/重置猜的...

猜数游戏c语言
printf("你猜的数据太大!\\n");} else { printf("你猜的数据太小!\\n");} } } printf("猜数游戏结束!\\n");return 0;} 测试结果:退出程序请按:ctrl + c!请输入你猜的数据(1-100): 50 你猜的数据太小!请输入你猜的数据(1-100): 75 你猜的数据太小!请输入你猜的数据(1-100)...

用c语言编写一个猜数游戏
include <stdio.h> include <stdlib.h> include define Range 100 int guess(int k){ int input;printf("请输入数字:\\t");scanf("%d",&input);if(input==k)return 1;if(input>k)return -1;if(input<k)return -2;} void score(int time){ if(time<5){printf("恭喜! Score: 100...

C语言 猜数字游戏
include<stdio.h> include include<math.h> int main(){ int i,a,n;srand((int)time(NULL));n=rand()%100+1;for(i=0; i<5; i++){ printf("请输入一个介于1到100的整数:");scanf("%d",&a);if(a<n)printf("猜小了!\\n");if(a>n)printf("猜大了!\\n");if(a==n){...

人机猜数游戏(用C语言写个程序)
int m;\/\/猜的数 int a[1000][3];int i,j;n=rand()%(9999-1000+1)+1000;while(1){ system("cls");printf("请输入您猜的数:");scanf("%d",&m);system("pause");a[time][0]=m;a[time][1]=Digit(n,m);a[time][2]=Position(n,m);time++;system("cls");printf("\\n您...

C语言编写猜数字游戏
include <stdlib.h> include <stdio.h> \/\/#include <iostream> unsigned char Num[4] = {0},getNum[4] = {0x20,0x20,0x20,0x20};void help(void){ char i =0,j = 0;for(i =0;i<4;i++){ for(j = 0;j<4;j++)if(Num[j] == getNum[i]){ if(i==j)printf("%dth...

易门县13827622372: 跪求一C程序高手一道猜数编程题
登宽达克: #include<stdio.h> #include<stdlib.h>int main() {int n;//给出的值int time;//次数int key;//输入的值char c;do{time=0;n=rand();while(time<10){scanf("%d",&key);if(key<n) printf("LESS THAN\n");else if(key>n) printf("GERATER...

易门县13827622372: 跪求C程序高手一道猜数编程题
登宽达克: void main() { int a,b,i=0,p=1; char c; { a=rand(); printf("Please input the data\n"); scanf("%d",&b); while(i<10&&p) { if(a==b){printf("\nWINER\n");p=0;} else {if(b>a)printf("\nGREATER THAN\n"); else printf("\nLESS THAN\n"); scanf("%...

易门县13827622372: 猜数游戏 c语言编程题 -
登宽达克: #include<iostream>#include<math.h> using namespace std; void main() { char a; for(a = 'c'; a != 'q';cin>>a) { int inNumber = 0; int guessCount = 0; int correctNumber = rand()%100; for(int i = 0 ; i < 10 ; i++) { cout<<">"; cin>>inNumber; if(...

易门县13827622372: 一道C语言猜数游戏编程题 -
登宽达克: #include "stdio.h"#include<time.h>#include<stdlib.h> void Guess(int magic, int guess) { static int c = 0; c++; if (magic == guess) { printf("\n你猜对了!\n你一共猜了%d次!", c); exit(0); } if (magic < guess) { printf("\n太大了!\n"); } else { ...

易门县13827622372: 猜数游戏C语言程序设计 -
登宽达克: 这道题不难,只要知道怎样用c语言生成1~100的随机数就很好办了!1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45附代码如下! #include<stdio.h> #include <...

易门县13827622372: 急求!!!!用C语言编写0 - 99之间的猜数游戏 -
登宽达克: 内容:设计一个猜数字游戏,它能根据游戏规则猜数. 功能:产生原始数字:产生4个随机数,并按任意顺序排列. 游戏提示:用1A2B形式提示玩家当前猜数字的匹配情况.例如1A表示玩家猜测的数字有1个与系统产生的原始数字符合,并...

易门县13827622372: c语言编程猜数字游戏 -
登宽达克: 分析: 先产生一个随机数N. 然后输入数I,如果A大于N,则提示大于信息. 如果I小于N,则提示小于信息. 直到I==N,则输出成功信息. 这是我用C语言写的. 环境: WIN-C ,TORBO C,如果是C++环境把倒数第二排getch();...

易门县13827622372: c语言,编写一个猜数字游戏 -
登宽达克: 太简单了,给你个编程思路吧: 输入甲猜的数 循环5次,每次都输入一个乙的数,并判断与甲数的关系 如果大则输出你猜的数据大了 如果小则输出你猜的数据小了 如果相同则输出你赢了!游戏结束.并结束程序 如果循环结束都没有猜对,就输出你输了,游戏结束,并输出甲输入的数据 提示:输入用scanf函数 循环可以用for循环 数据可以用整形

易门县13827622372: 兄弟我跪求一个用c语言编的的人与计算机猜数字的游戏的程序,要求在计算机猜数字结束后显示总步数,总时间 -
登宽达克: 测试结果: 开始时间:Fri Apr 20 00:29:05 2012请输入您猜的那个数:50第1次猜测,很遗憾您猜大了!请输入您猜的那个数:25第2次猜测,很遗憾您猜大了!请输入您猜的那个数:12第3次猜测,很遗憾您猜小了!请输入您猜的那个数:18...

易门县13827622372: 急求C语言猜数字游戏的程序设计 ?
登宽达克: 简单~ 用rand() % 11;产生 0 - 9的数字 然后根据他所猜的数字 进行比较 伪代码: const int m = 5; size_t y = 0; while(scanf("%d",&n) != EOF) { if (y == m){cout<<"超过5次"<<endl;break;} int x = rand() % 11; if (x >= 10)-- x; switch(n) { case n > ...

本站内容来自于网友发表,不代表本站立场,仅表示其个人看法,不对其真实性、正确性、有效性作任何的担保
相关事宜请发邮件给我们
© 星空见康网