是否可以使用for循环显示相邻的两个多维数组
Is it possible to display two multi-dimensional arrays next to each other using a for loop
我正在尝试用C++输出多个多维数组,需要一些帮助来理解循环为什么以及如何在它们所在的位置显示输出。我希望输出我的第一个多维阵列,然后在它的右边输出我的第二个多维阵列。我可以让我的第二个多维数组在第一个数组下面输出,但不能在它旁边输出,否则会让一切看起来一团糟。下面是我希望我的代码如何输出的示例。
first second
12 34 23 34 56 67
32 77 56 34 54 56
下面是我必须输出我的第一个多维数组的代码。谢谢你抽出时间。
#include <iostream>
#include <conio.h>
#include <iomanip>
using namespace std;
int main()
{
int a[2] [3] =
{
{ 16, 18, 23 },
{ 54, 91, 11 }
};
int b[2][3] =
{
{ 14, 52, 77 },
{ 16, 19, 59 }
};
for (int row = 0; row < 2; row++)
{
for (int column = 0; column < 3; column++)
{
cout << a[row][column] << " ";
}
cout << endl;
}
_getch();
return 0;
}
您可以尝试使用3个for循环,一个用于行数(将包围另外两个用于循环),然后对第一个数组的列使用for循环,然后输出几个空格,然后对第二个数组的行使用第三个for循环。
例如:
for(i = 0; i < num_rows; i++)
{
for(j = 0; j < num_cols_1; j++)
{
// print j'th element in i'th row of array 1
}
// print some spaces
for(j = 0; j < num_cols_2; j++)
{
// print j'th element in i'th row of array 2
}
}
相关文章:
- 将fold表达式与std::一起用于两个元组
- 如何在C++中比较两个char数组
- 在c++中获取两个大int,并将它们存储在数组中
- 如何以优化的方式同时迭代两个间距不相等的数组
- 运算符重载 (+),用于添加两个具有 C++ 的数组
- 将字符串拆分为标记,并将标记拆分为两个单独的数组
- 可以将两个相同类型的连续数组视为一个数组吗?
- C++递归来决定数组中的两个值
- 如何将字符串和整数读取到两个单独的动态数组中的程序编写?
- 按 Tab 单步执行两个控制组
- 如何检查两个元组的所有成员是否不同
- C 通过随机选择其元素从两个元组制成元组
- 如何将两个元组作为C 的参数发送
- 对于同一循环的这两个连续组,是否有更有效的解决方案
- 在 C++11 中加入两个元组
- 将两个双数组集组合为一个查找其并集和交集的最简单方法
- 如何创建一个在 C++11 (STL) 中压缩两个元组的函数
- 快速实现两个 8 位数组的协方差
- 如何绑定两个元组
- 将一个16位整数复制到一个两字节数组