·首页 ·asp ·.net ·php ·JSP ·CGI ·数据库 ·网页设计 ·网管专栏 ·XML ·工具软件 ·办公软件 ·操作系统 ·程序设计 ·LINUX 
  当前位置: 普克>>计算机教程>>程序设计>>CC++>>关于文曲星上猜数字游戏的c编程方法
flash视频教学

photoshop专题

asp.net专题

office专题

关于文曲星上猜数字游戏的c编程方法


CC++ 发表时间:2006-4-8 字体:  返回

    本人为计算机专业大一新生,出学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<=SIZE-1;i++)
             a[i]=rand()%10;
        for(i=0;i<=SIZE-1;i++)                   
        {    for(j=i+1;j<=SIZE-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<=6)
    {   printf("Please guess the number:\n");
        scanf("%d",&guessnum);
        for(i=0;i<=SIZE-1;i++)
           b[i]=guessnum/(int)pow(10,SIZE-1-i)%10;           
        countera=0;
        for(i=0;i<=SIZE-1;i++)
            {   if(a[i]==b[i])  countera++;}
        counter0=0;
        for(i=0;i<=SIZE-1;i++)
            {   for(j=0;j<=SIZE-1;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编程方法的相关内容]   [在狗狗中搜索关于文曲星上猜数字游戏的c编程方法的相关内容]
Copyright @ 2006 PUPK.COM 普克创业投资网 版权所有
 建议使用1024*768以达到最好的浏览效果