You are here:

C++/help me with this program.


write a c++ program that adds equivalent elements of the two -dimensional; arrays named first and second. both arrays sholud have two rows and three columns. for example, element [1][2] of the resulting array should be the sum of first [1][2]. the first and second arrays should bi initialized as follows:
16 18 23  24 52 77
54 91 11  16 19 59

using namespace std;
int main()
  int i,j;
  int val[2][3]={{16,23,52},{54,11,19}};

   int value[2][3]={{18,24,77},{91,16,59}};

  cout<<"       FIRST";
   cout<<"\t\t" << "SECOND";
     cout << endl;
  cout<<endl << endl;
  return 0;

Some pointers:

1) Instructions say "2 arrays named first and second".

2) You need an array to hold the result (the problem is to add 2 arrays, right?)

3) The 2 loops are good, but you need to add the elements as you go, into the result array.  You could output the result array as you go if you wanted to.



All Answers

Answers by Expert:

Ask Experts


Bill A


I can answer questions about C++, programming algorithms, Windows programming in MFC (which is C++). I cannot answer questions about STL (templates) and I have no experience with Linux. I do enjoy reviewing code and critiquing it or finding problems in it. I will also gladly show better algorithms or methods if you want to take advantage of that.


I've developed a commercial embedded C compiler/assembler and IDE with debugger toolset, of which the IDE and debugger are written in C++. I work in the industry writing high tech embedded programs and Windows programs to communicate with the embedded devices.

Book: Embedded Systems Design using the Rabbit 3000 Microprocessor Authored Chapter 10 in its entirety.

BS Computer Engineering

©2016 All rights reserved.