如果是要做猜数字 这样不知对不对
#include<stdlib.h>
main()
{
int x,a[4],b[4],k,s,i,j,t;
k=0;
s=0;
randomize();
a[0]=random(10);
a[1]=random(10);
a[2]=random(10);
a[3]=random(10);
for(t=1;t<=3;t++)
{
printf("\ninput the number:\n");
scanf("%d",&x);
b[0]=x/1000;
b[1]=x/100%10;
b[2]=x/10%10;
b[3]=x%10;
for(i=0;i<=3;i++)
{
for(j=0;j<=3;j++)
{
if(b[i]==a[j])
k=k+1;
if(b[i]==a[j]&&b[i+1]==a[j+1])
s=s+1;
if(x==1000*a[0]+100*a[1]+10*a[2]+a[3])
t=3;
}
}
printf("\n%dA,%dB",k,s);
k=0;
s=0;
}
printf("\nthe number is%d%d%d%d",a[0],a[1],a[2],a[3]);
getch();
}
#include<stdlib.h>
main()
{
int x,a[4],b[4],k,s,i,j,t;
k=0;
s=0;
randomize();
a[0]=random(10);
a[1]=random(10);
a[2]=random(10);
a[3]=random(10);
for(t=1;t<=3;t++)
{
printf("\ninput the number:\n");
scanf("%d",&x);
b[0]=x/1000;
b[1]=x/100%10;
b[2]=x/10%10;
b[3]=x%10;
for(i=0;i<=3;i++)
{
for(j=0;j<=3;j++)
{
if(b[i]==a[j])
k=k+1;
if(b[i]==a[j]&&b[i+1]==a[j+1])
s=s+1;
if(x==1000*a[0]+100*a[1]+10*a[2]+a[3])
t=3;
}
}
printf("\n%dA,%dB",k,s);
k=0;
s=0;
}
printf("\nthe number is%d%d%d%d",a[0],a[1],a[2],a[3]);
getch();
}
粗心是大敌