您好,欢迎来电子发烧友网! ,新用户?[免费注册]

您的位置:电子发烧友网>源码下载>数值算法/人工智能>

人机猜数游戏源代码

大小:155 人气: 2010-02-09 需要积分:0
{$username}的空间

用户级别:注册会员

贡献文章:

贡献资料:

人机猜数游戏源代码
#include "time.h"
#include "stdlib.h"
#include
#include
void guess1( )
{
 int Password=0,Number=0,price=58,i=0;
 clrscr();
 printf("\n====This is a Number Guess Game!====\n");
 while( Password != 1234 )
 {
  if( i >= 3 )
   return;
  i++;
  puts("Please input Password: ");
  scanf("%d",&Password);
 }
 
 i=0;
 while( Number!=price )
 {
  do{
   puts("Please input a number between 1 and 100: ");
   scanf("%d",&Number);
   printf("Your input number is %d\n",Number);
  }while( !(Number>=1 && Number<=100) );
  if( Number >= 90 )
  {
   printf("Too Bigger! Press any key to try again!\n");
  }
  else if( Number >= 70 && Number < 90 )
  {
   printf("Bigger!\n");
  }
  else if( Number >= 1 && Number <= 30 )
  {
   printf("Too Small! Press any key to try again!\n");
  }
  else if( Number > 30 && Number <= 50 )
  {
   printf("Small! Press any key to try again!\n");
  }
  else
  {
   if( Number == price )
   {
    printf("OK! You are right! Bye Bye!\n");
   }
   else if( Number < price )
   {
    printf("Sorry,Only a little smaller! Press any key to try again!\n");
 
   }
   else if( Number > price )
    printf(" Sorry, Only a little bigger! Press any key to try again!\n");
  }
  getch();
 }
}
 
void  guess2( )
{ int y,stime,a,z,t,i,c,m,g,s,j=0,k=0,b[4],l[4];
  long ltime;
  ltime=time(NULL);
  stime=(unsigned int)ltime/2;
  srand(stime);
  z=random(9999);
  printf("I have a number with 4 digits in mind,please guess.\n");
  for(c=1;;c++)
  { printf("Enter a number with 4 digits:");
    scanf("%d",&g);
    a=z;j=0;k=0;
    l[0]=l[1]=l[2]=l[3]=0;
    for (i=1;i<5;i++)
    { s=g;m=1;
      for (t=1;t<5;t++)
      { if (a%10==s%10)
 { if (m&&t!=l[0]&&t!=l[1]&&t!=l[2]&&t!=l[3])
   { j++;m=0;l[j-1]=t;
   }
   if (i==t)

 
void swap1(float *p1,float *p2)
{float temp;
 temp=*p1;*p1=*p2;*p2=temp;
}
void swap2(char **p1,char **p2)
{char *temp;
 temp=*p1;*p1=*p2;*p2=temp;
}
void sort(char *code[],char *name[],float *score1,float *score2,
float *score3,float *aver,int n)
{int i,j;
 for (i=0;i   for (j=i+1;j     if (aver[i]     { swap1(aver+i,aver+j) ;
       swap1(score1+i,score1+j);
       swap1(score2+i,score2+j);
       swap1(score3+i,score3+j);
       swap2(&name[i],&name[j]);
       swap2(&code[i],&code[j]);
     }
简易计算器源代码
#include
int operator1,operator,first,second,result;
displaycalculator()
{clrscr();
 printf("+-------------------\n");
 printf("| Simple Caculator |\n");
 printf("+-------------------\n");
 printf("|                  |\n");
 printf("+----+----+----|----\n");
 printf("|    |  / |  * | - |\n");
 printf("+----+----+----|----\n");
 printf("|  7 |  8 |  9 |   |\n");
 printf("+----+----+----| + |\n");
 printf("|  4 |  5 |  6 |   |\n");
 printf("+----+----+----|---|\n");
 printf("|  1 |  2 |  3 |   |\n");
 printf("+----+----+----| = |\n");
 printf("|  0      |  . |   |\n");
 printf("+---------+----|---|\n");
}
getdata()
{int c,n=0;
 do
 { c=getch();
   if (c>='0' && c<='9')
   { putch(c);
     n=n*10+c-0x30;
   }
   if (c=='\b' && wherex()>2)
   { putch(c);putch(0x20);putch(c);
     n/=10;
   }
 }while (!(c==27||c=='+'||c=='-'||c=='*'||c=='/'||c=='\n'));
 operator=c;
 if (c!=27&&c!='\n') putch(c);
 return (n);
}
calculate()
{ if (operaor1=='+')
   result=first+second;
  else if (operaor1=='-')
   result=first-second;
  else if (operaor1=='*')
   result=first*second;
  else
   result=first/second;
}
displayresult()
{ gotoxy(2,4);
  printf("             ");
  gotoxy(2,4);
  printf("%d",result);
  if (operator!=13 && operator!=27) putch(operator);
}
main()
{ displaycalculator();
  gotoxy(2,4);
  first=getdata();
  while (operator!=27)
  { operator1=operator;
    second=getdata();
    displayresult();
    first=result;
  }

非常好我支持^.^

(8) 100%

不好我反对

(0) 0%

      发表评论

      用户评论
      评价:好评中评差评

      发表评论,获取积分! 请遵守相关规定!