C语言猜数游戏代码
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
#include
#include
#include
#include
int i;
long int rn();
void fun();
void gc();
int input(long int);
void grade(int);
int welcome();
int compare(long int,long int);
void choise(int *,int);
void main()
{
system("cls");
printf("\n\n\n\t\t* * * * * * * * welcome * * * * * * * *");
printf("\n\n\n");
printf("\t\t\tmaker: xiachao xiaoyuyan");
printf("\n\n\n\t\t\tuse enter to be continue");
getch();
fun();
}
void fun()
{
int b,s,g;
long int a;
system("cls");
s=welcome();
if(s==1)
{
system("cls");
a=rn();
b=input(a);
grade(b);
gc();
}
if(s==2)
{
system("cls");
printf("\n\n\n\n\n");
printf("\t
---------------------------------------------------------\n");
printf("\t|game rules: |\n");
printf("\t|
|\n");
printf("\t|input your number(10000--99999),it will compare to the |\n");
printf("\t|
|\n");
printf("\t|system's number(10000--99999),and the number doesn't have|\n");
printf("\t|
|\n");
printf("\t|same digit. |\n");
printf("\t|
|\n");
printf("\t|if your number as same as system,your win,else try again.|\n");
printf("\t|
|\n");
printf("\t ---------------------------------------------------------");
gc();
}
if(s==3)
{
printf("\n\n\t\t\tThanks for your using.\n");
printf("\t\t\t\tBye Bye!");
getch();
exit(0);
}
}
long int rn()
{
int b,d;
long int c;
unsigned long int a;
int array[5];
time_t t;
time(&t);
srand(t);
loop1:a=10000+rand() % 90000;
c=a;
for(i=0;i<5;i++)
{
array[i]=c%10;
c=c/10;
}
choise(array,5);
b=array[0];
for(i=1;i<5;i++)
{
if(b==array[i])
goto loop1;
else
b=array[i];
}
return a;
}
void choise(int *num,int n)
{
int j,k;
for(i=1;i { k=num[i]; j=i-1; while((j>=0)&&(num[j]>k)) { num[j+1]=num[j]; j--; } num[j+1]=k; } } int compare(long int a,long int b) { int c; if(a>b) { printf("\t\t\tneed greater!"); printf("( >%ld )\n",b); c=0; } if(a { printf("\t\t\tneed less!"); printf("( <%ld )\n",b); c=0;