| 導購 | 订阅 | 在线投稿
分享
 
 
 

關于文曲星上猜數字遊戲的c編程方法

來源:互聯網  2008-06-01 02:05:06  評論

本人c語言能力有限,但也希望能與廣大c語言愛好者進行交流,現將我自己編的文曲星上的猜數字遊戲的c原程序代碼公布如下(郵箱:pegasusknight@vip.sina.com,歡迎大家與我交流)

#include<stdio.h>

#include<stdlib.h>

#include<time.h>

#include<math.h>

#define SIZE 4

main()

{

int enter=1,stop,a[SIZE],b[SIZE],guessnum,i,j,counter,countera,counterb,counter0,extra;

char ch;

srand(time(NULL));

while(enter==1)

{ stop=2;

while(stop==2)

{ extra=1;

for(i=0;i

a[i]=rand()%10;

for(i=0;i

{ for(j=i+1;j

{ if(a[i]==a[j]) extra=2; }

}

if(a[0]!=0&&extra==1) {stop=1;PRintf("%d%d%d%d",a[0],a[1],a[2],a[3]);}

}

counter=1;

while(counter

{ printf("Please guess the number:\n");

scanf("%d",&guessnum);

for(i=0;i

b[i]=guessnum/(int)pow(10,SIZE-1-i)%10;

countera=0;

for(i=0;i

{ if(a[i]==b[i]) countera++;}

counter0=0;

for(i=0;i

{ for(j=0;j

{if(a[i]==b[j]) counter0++;}

}

counterb=(counter0-countera);

if(countera==4) {printf("Wonderful!You guessed the number.Then,please input your choice,'1' represents going on,'2' represents breaking\n");

counter=7;

scanf("%d",&enter);

}

else {printf("%dA%dB\n",countera,counterb);

counter++;

}

}

}

while((ch=getchar())!='s'&&ch!='S');

return 0;

}

關于文曲星上猜數字遊戲的c編程方法
更多內容請看java編程開發手冊 網絡遊戲攻略 遊戲開發專題,或

本人c語言能力有限,但也希望能與廣大c語言愛好者進行交流,現將我自己編的文曲星上的猜數字遊戲的c原程序代碼公布如下(郵箱:pegasusknight@vip.sina.com,歡迎大家與我交流) #include<stdio.h> #include<stdlib.h> #include<time.h> #include<math.h> #define SIZE 4 main() { int enter=1,stop,a[SIZE],b[SIZE],guessnum,i,j,counter,countera,counterb,counter0,extra; char ch; srand(time(NULL)); while(enter==1) { stop=2; while(stop==2) { extra=1; for(i=0;i a[i]=rand()%10; for(i=0;i { for(j=i+1;j { if(a[i]==a[j]) extra=2; } } if(a[0]!=0&&extra==1) {stop=1;PRintf("%d%d%d%d",a[0],a[1],a[2],a[3]);} } counter=1; while(counter { printf("Please guess the number:\n"); scanf("%d",&guessnum); for(i=0;i b[i]=guessnum/(int)pow(10,SIZE-1-i)%10; countera=0; for(i=0;i { if(a[i]==b[i]) countera++;} counter0=0; for(i=0;i { for(j=0;j {if(a[i]==b[j]) counter0++;} } counterb=(counter0-countera); if(countera==4) {printf("Wonderful!You guessed the number.Then,please input your choice,'1' represents going on,'2' represents breaking\n"); counter=7; scanf("%d",&enter); } else {printf("%dA%dB\n",countera,counterb); counter++; } } } while((ch=getchar())!='s'&&ch!='S'); return 0; } [url=/bbs/detail_1785337.html][img]http://image.wangchao.net.cn/it/1323423841986.gif[/img][/url] 更多內容請看java編程開發手冊 網絡遊戲攻略 遊戲開發專題,或
󰈣󰈤
王朝萬家燈火計劃
期待原創作者加盟
 
 
 
>>返回首頁<<
 
 
 
 
 熱帖排行
 
 
 
靜靜地坐在廢墟上,四周的荒凉一望無際,忽然覺得,淒涼也很美
© 2005- 王朝網路 版權所有