比这篇新的文章:
验证歌德巴赫猜想
比这篇旧的文章: hello
作者: zackchen, 点击502次, 评论(3), 收藏者(0)
打分:
所有评论,共3条:( 我也来说两句)
比这篇旧的文章: hello
猜数字游戏
语言: C, 标签: 猜数字 游戏 2008/07/12发布 6个月前更新作者: zackchen, 点击502次, 评论(3), 收藏者(0)
C语言: 猜数字游戏
01 /*******************************************/
02 /* 作者:Zack Chen
03 /* 时间:2008年7月12日
04 /* 网站:zack.cublog.cn
05 /*******************************************/
06
07 #include<stdio.h>
08 #include<stdlib.h>
09 #include<time.h>
10
11 int main()
12 {
13 srand(time(NULL));
14 int a=rand()%10,b,c,d;
15 b=c=d=a;
16 if(a==0) /*防止千位上出现0*/
17 a=a+1;
18 for(;b==a;)
19 {
20 b=rand()%10;
21 }
22 for(;c==a||c==b;)
23 {
24 c=rand()%10;
25 }
26 for(;d==a||d==b||d==c;)
27 {
28 d=rand()%10;
29 }
30
31 int i,e,f,g,h,input,x=0,y=0;
32 for(i=1;i<=25&&x!=4;i++)/* 25次以内解决 */
33 {
34 printf("第%d次\n",i);
35 scanf("%d",&input);
36 e=input/1000;/* 分解输入的数字 */
37 f=input/100-e*10;
38 h=input%10;
39 g=(input%100-h)/10;
40 if(e==f||e==g||e==h||f==g||f==h||g==h)
41 {
42 printf("输入错误,任意两数必不会重复。\n请重新输入。\n");
43 x=y=0;
44 i--;
45 }
46 else
47 {
48 {
49 if(a==e)
50 x++;
51 if(b==f)
52 x++;
53 if(c==g)
54 x++;
55 if(d==h)
56 x++;
57 }
58 {
59 if(a==f||a==g||a==h)
60 y++;
61 if(b==e||b==g||b==h)
62 y++;
63 if(c==e||c==f||c==h)
64 y++;
65 if(d==e||d==f||d==g)
66 y++;
67 }
68 if(x==4)
69 printf("答对了!\n");
70 else
71 {
72 printf("%dA%dB",x,y);
73 x=y=0;
74 }
75 if(i==25&&x!=4)
76 printf("正确答案是%d%d%d%d\n",a,b,c,d);
77 }
78 }
79 return 0;
80 }
02 /* 作者:Zack Chen
03 /* 时间:2008年7月12日
04 /* 网站:zack.cublog.cn
05 /*******************************************/
06
07 #include<stdio.h>
08 #include<stdlib.h>
09 #include<time.h>
10
11 int main()
12 {
13 srand(time(NULL));
14 int a=rand()%10,b,c,d;
15 b=c=d=a;
16 if(a==0) /*防止千位上出现0*/
17 a=a+1;
18 for(;b==a;)
19 {
20 b=rand()%10;
21 }
22 for(;c==a||c==b;)
23 {
24 c=rand()%10;
25 }
26 for(;d==a||d==b||d==c;)
27 {
28 d=rand()%10;
29 }
30
31 int i,e,f,g,h,input,x=0,y=0;
32 for(i=1;i<=25&&x!=4;i++)/* 25次以内解决 */
33 {
34 printf("第%d次\n",i);
35 scanf("%d",&input);
36 e=input/1000;/* 分解输入的数字 */
37 f=input/100-e*10;
38 h=input%10;
39 g=(input%100-h)/10;
40 if(e==f||e==g||e==h||f==g||f==h||g==h)
41 {
42 printf("输入错误,任意两数必不会重复。\n请重新输入。\n");
43 x=y=0;
44 i--;
45 }
46 else
47 {
48 {
49 if(a==e)
50 x++;
51 if(b==f)
52 x++;
53 if(c==g)
54 x++;
55 if(d==h)
56 x++;
57 }
58 {
59 if(a==f||a==g||a==h)
60 y++;
61 if(b==e||b==g||b==h)
62 y++;
63 if(c==e||c==f||c==h)
64 y++;
65 if(d==e||d==f||d==g)
66 y++;
67 }
68 if(x==4)
69 printf("答对了!\n");
70 else
71 {
72 printf("%dA%dB",x,y);
73 x=y=0;
74 }
75 if(i==25&&x!=4)
76 printf("正确答案是%d%d%d%d\n",a,b,c,d);
77 }
78 }
79 return 0;
80 }
所有评论,共3条:( 我也来说两句)
| 1 |
半瓶墨水
6个月前
回复
这个缩进看起来好陌生啊。。。
|
| 2 |
我是这里的新人啊,前些天才发现这个网站,觉得不错。
|
| 3 |
@zackchen
|
代码