c++ - Is it possible to add two multi-dimensional arrays together to a third multi-dimensional array -



c++ - Is it possible to add two multi-dimensional arrays together to a third multi-dimensional array -

i attempting add together 2 multi-dimensional arrays 3rd array without much success.the first 2 arrays created have values , unsure of how add together multi-dimensional array multi-dimensional array b hand have value place in mult-directional array c. below started come up.

thanks in advance time , skills.

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]; (int rows = 0; rows < 2; rows++) { (int columns = 0; columns < 3; columns++) { c[rows][columns] = b[rows][columns] + a[rows][columns]; } } _getch(); homecoming 0; }

one way shorter: flatten pointers , utilize transform.

int c[2][3]; std::transform( *a, *std::end(a), *b, *c, std::plus<int>() ); // or plus<> since c++14

c++ arrays multidimensional-array

Comments

Popular posts from this blog

Delphi change the assembly code of a running process -

json - Hibernate and Jackson (java.lang.IllegalStateException: Cannot call sendError() after the response has been committed) -

C++ 11 "class" keyword -