怎样比较《C语言》两个int型数组中的数是一样的?

如题所述

/* i 代表1 ~ 9 数字,可以用你想要的数组代替 */
/*a[j] 你要验证是否存在1 ~ 9的数组*/
bool bRight = true;
int a[9] = {1,2,3,4,5,6,7,8,9};
int b[9] = {2,4,3,1,7,9,5,8,6};
for(int i=0;i<9;i++)
{
for(int j=0;j<9;j++)
{
if(a[i] != -1 &&  b[j] == a[i])
{
a[i] = -1;        //将出现过的数字拉黑,防止相同值重复判断
break;
}
if(j == 8)
{
bRight  = false;
cout << "没有数字<" <<a[i]<<">"<<endl;
}
}
}
if(bRight ) cout << "相同" <<endl;
else cout << "不相同" <<endl;

温馨提示:答案为网友推荐,仅供参考
相似回答