How can I use a for loop to load elements into each of my arrays and then output the sum of each array into a sum array?

Hello Everyone,
I am working on a C++ application that will load elements into the first array which is 10 rows by 10 columns and will load elements into a second array that is also a 10 by 10 and then add each array elements together and put them in an array called sum. For example, in real when you do addition of matrices, you would do something like this below, but my arrays are more complex then this. The question is how I can use a nested for loop to load elements into each of my arrays. Any examples would be much appreciated!!! Here is the code I have so far. I know how to output elements in an array, but I never loaded elements into an array using for loop. The comment part where you see the nested for loop going through the elements row by column and then storing them into the first array, I am not to sure about. Can someone please help me or refer me to some online resources?

[1 2 4] + [2 3 7]= [3 5 11]

 
#include "stdafx.h" 
#include <iostream> 
#include <cstdlib>
#include <string> 
using namespace std;   
int main() 
{ 
 
   /* 
 
  For this version, the matrices are square (defined by size, which is a maximum of 10).  
  Thus, m & n (rows & columns) are the same.   
  Later versions can allow the number of rows and columns to be different. 
 
   size - the dimension of both matrices.  
   m - the number of rows   
   n - the number of columns  
   c - the delimiter of the outer loop         
   d - the delimiter of the inner loop 
 
   first  - the first matrix  
   second - the second matrix 
   sum - holds the sum of the 2 matrices 
 
    */ 
 
      int size, m, n, c, d, first[10][10], second[10][10], sum[10][10]; 
 
     cout << "Enter the number of rows and columns of matrices: ";         
     cin >> size;  m = size; n = size;    

     
    /* for (int i=0; i<size; ++i)
      {
        for (int j=0; j<size; ++j)
        {
          cout << "first[" << i << "][" << j << "]" <<endl;
          cin >> first[i][j]; 
        }
      }
    */ 


    // Load the first matrix 

      cout << "Enter the elements of first matrix: "; 
 


    // Load the second matrix    
     
     /* for (int i=0; i<size; ++i)
       {
          for (int j=0; j<size; ++j)
          {
            cout << "second[" << i << "][" << j << "]" <<endl;
            cin >> second[i][j];
          }
        }
    */ 
    
    cout << "Enter the elements of second matrix: ";    
     
   // Sum the elements of the matrices 
 
   // Print the sum matrix
 
   cout << "Hit any key to continue" << endl; 
 
    system ("pause");    return 0; 
} 

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.