是随机的
#include<iostream.h>
void main()
{
int a[4],b[4],i,j,n1 = 0,n2 = 0;
for(i = 0;i<4;i++)
{
a[i] = random(1,10,1);
}
cout<<"请输入你的数字:(4位):"<<endl;
for(i = 0;i<4;i++)
cin>>b[i];
for(i = 0;i<4;i++)
if(a [i] == b[i])
n1++;
for(i = 0;i<4;i++)
for(j = 0;j<4;j++)
{ if(a[i] == b[j])
n2++;
}
cout<<n1<<"A"<<n2-n1<<"B"<<endl;
}
不是随机的
#include<iostream.h>
void main()
{
int a[4],b[4],i,j,n1 = 0,n2 = 0;
for(i = 0;i<4;i++)
{
a[i] = random(1,10,1);
}
cout<<"请输入你的数字:(4位):"<<endl;
for(i = 0;i<4;i++)
cin>>b[i];
for(i = 0;i<4;i++)
if(a [i] == b[i])
n1++;
for(i = 0;i<4;i++)
for(j = 0;j<4;j++)
{ if(a[i] == b[j])
n2++;
}
cout<<n1<<"A"<<n2-n1<<"B"<<endl;
}
试试