如图,那么这个问题用数组来表达不就是a[]={1,2,3} b[]={2,3,4} 则输出a[]={1,2,3,4}吗??我是这样实现的 #include
using namespace std;
int main()
{
int a[] = {0};
cout << "请输入数组a的元素:" << endl;
for (int i = 0; i < 3; i++)
{
cin >> a[i];
}
for (int x = 0; x < 3; x++)
{
cout << a[x] << " ";
}
cout << endl;
cout << "请输入b数组的元素:" << endl;
int b[] = { 0 };
for (int j = 0; j < 3; j++) //循环输入
{
cin >> b[j];
}
for (int x = 0; x < 3; x++) //然后输出看下
{
cout << b[x] << " ";
}
cout << endl;
for (int j = 0; j < 3;j++) //j为数组b的下标
for (int i = 0; i < 3; i++) // i为数组a的下标
{
if (a[i] == b[j]) // 如果
{
continue;
}
else
{
a[sizeof(a)] = b[j]; //将满足条件的b值插入到数组a中的
}
}
cout << b[sizeof(a)] << endl;
cout << "此时数组a的元素为:" << endl;
for (int x = 0; x <sizeof(a); x++)
{
cout << b[x] <<" ";
}
system("pause");
return 0;
}请问错在哪?!定义好的数组定长不可插入?!