我如何从一个数组中添加数据并将其作为列放置在预先存在的数组中。
example
double array[3][2];
打印时:
3 2
5 5
7 8
我还有另一个包含其他信息的数组
double arrayb[3]={1,1,1};
我想运行 for 循环并能够打印
for (int i=0; i<3; i++){
for (int j=0; j<3; j++){
cout << array[i][j];}}
这就是我想看到的:
3 2 1
5 5 1
7 8 1
最佳答案
试试这个:
for (int i=0; i<3; i++) {
// You have only two elements in array[i], so the limit should be 2
for (int j=0; j<2; j++) {
// Leave some whitespace before the next item
cout << array[i][j] << " ";
}
// Now print the element from arrayb
cout << arrayb[i] << endl;
}
关于c++ - 在 c 中的二维数组的末尾添加一个额外的数据列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16845929/