关于c++primer习题判断练个数组是否想等的问题!
#include<iostream>usingnamespacestd;intmain(){constintarr_size=6;intia1[arr_size],ia2...
#include <iostream>
using namespace std;
int main()
{
const int arr_size = 6;
int ia1[arr_size], ia2[arr_size];
size_t ix;
cout << "Enter " << arr_size
<< " numbers for array1:" << endl;
for (ix = 0; ix != arr_size; ++ix)
cin >> ia1[ix];
cout << "Enter " << arr_size
<< " numbers for array2:" << endl;
for (ix = 0; ix != arr_size; ++ix)
cin >> ia2[ix];
for (ix = 0; ix != arr_size; ++ix)
if (ia1[ix] != ia2[ix]) {
cout << "Array1 is not equal to array2." << endl;
return 0;
}
cout << "Array1 is equal to array2." << endl;
return 0;
}
求教for(ix =0;ix !=arr_size;ix++)
cin>>ia1[ix]; 这个for循环的作用,求详细解释,谢谢 展开
using namespace std;
int main()
{
const int arr_size = 6;
int ia1[arr_size], ia2[arr_size];
size_t ix;
cout << "Enter " << arr_size
<< " numbers for array1:" << endl;
for (ix = 0; ix != arr_size; ++ix)
cin >> ia1[ix];
cout << "Enter " << arr_size
<< " numbers for array2:" << endl;
for (ix = 0; ix != arr_size; ++ix)
cin >> ia2[ix];
for (ix = 0; ix != arr_size; ++ix)
if (ia1[ix] != ia2[ix]) {
cout << "Array1 is not equal to array2." << endl;
return 0;
}
cout << "Array1 is equal to array2." << endl;
return 0;
}
求教for(ix =0;ix !=arr_size;ix++)
cin>>ia1[ix]; 这个for循环的作用,求详细解释,谢谢 展开
1个回答
展开全部
for(ix =0;ix !=arr_size;ix++) //循环直到ix == arr_size ,也就是你变量定义的大小
cin>>ia1[ix]; //读入一个数到ia[ix], ix从0-5
cin>>ia1[ix]; //读入一个数到ia[ix], ix从0-5
追问
还是有点不懂,我想了一会儿觉得是这样的: 输入一组数,比如我输的是 2 3 4 5 6 7,这几个数的在数组的位置就是按照输入的顺序a[0] a[1] ..a[5]保存吗?
追答
是的,循环是从0到n 而这里退出条件是ix != arr_size, 当ix = 6时为假
所以这里循环是从0到5
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询