是否可以将两个多维数组一起添加到第三个多维数组中
Is it possible to add two multi-dimensional arrays together to a third multi-dimensional array
我试图将两个多维数组一起添加到第三个数组中,但没有成功。我创建的前两个数组都有值,我不确定如何将多维数组a添加到多维数组b中,并将值正确地放在多向数组c中。以下是我开始想到的。
提前感谢您的时间和技能。
int main()
{
int a[2] [3] =
{
{ 16, 18, 23 },
{ 54, 91, 11 }
};
int b[2][3] =
{
{ 14, 52, 77 },
{ 16, 19, 59 }
};
int c[2][3];
for (int rows = 0; rows < 2; rows++)
{
for (int columns = 0; columns < 3; columns++)
{
c[rows][columns] = b[rows][columns] + a[rows][columns];
}
}
_getch();
return 0;
}
缩短指针长度的一种方法是:压平指针并使用transform
。
int c[2][3];
std::transform( *a, *std::end(a), *b, *c, std::plus<int>() ); // Or plus<> since C++14
相关文章:
- 使用嵌套函数数组是个好主意吗?
- 为什么我需要三个嵌套的大括号来调用赋值运算符,将const引用到二维数组
- 链表数组(5 个队列)
- 是否有可能通过溢出 C 中的第一个元素来写入数组第二个元素
- 数组中最大的三个数字
- 五个中三个最大参数的平均值,不使用排序算法或向量/数组
- 如何使用三个参数化构造函数的rand()函数初始化对象的数组
- 2D数组-将三个元素与if语句进行比较
- 如何按第一个,然后是第二个,然后是第三个对 2d 数组进行排序,..使用 C++ 的列
- 指向数组第一个元素的指针的地址
- 用 std::valarray 替换 POD C 样式数组是个坏主意吗?
- 将动态数组的三个元素复制到另一个元素中
- 对包含三个项目的数组进行排序
- OpenGL:两个顶点数组 + 两个索引数组
- c++多维数组多个数据类型
- C++ 如何根据分隔符序列将文件读入多维数组或三个单独的数组
- 是否可以将两个多维数组一起添加到第三个多维数组中
- 使用C++AMP处理大型数组(65536+个元素)
- 如何将字符串的三个字符放入数组的一个空间中
- 在c++中使用MKL函数初始化数组是个好主意吗?