Difference between revisions of "Adding Two Matrices"

From CompSciWiki
Jump to: navigation, search
Line 3: Line 3:
 
|Problem= To solve this problem you must use nested loops to add two matrices together.  If you have not yet taken the course on Matrices and Linear Algebra yet, do not worry.  For our purposes we will consider a matrix to simply be a two dimensional array.  You may consider the number of columns to be our main array.  Our rows will be represented as arrays held within each column.  After this has been considered, adding one matrix to the other is simple.
 
|Problem= To solve this problem you must use nested loops to add two matrices together.  If you have not yet taken the course on Matrices and Linear Algebra yet, do not worry.  For our purposes we will consider a matrix to simply be a two dimensional array.  You may consider the number of columns to be our main array.  Our rows will be represented as arrays held within each column.  After this has been considered, adding one matrix to the other is simple.
  
Use these two arrays as the variables in your code, or you may use your own if you wish:
+
Use these two arrays as the variables in your code, or you may use your own if you wish:<BR>
int M1[3][3] = {{1,2,3},{4,5,6},{7,8,9}};
+
int M1[3][3] = {{1,2,3},{4,5,6},{7,8,9}};<BR>
int M2[3][3] = {{9,8,7},{6,5,4},{3,2,1}};
+
int M2[3][3] = {{9,8,7},{6,5,4},{3,2,1}};<BR>
  
 
|SideSection=
 
|SideSection=

Revision as of 10:53, 1 April 2010

Back to the Program-A-Day homepage

Problem

To solve this problem you must use nested loops to add two matrices together. If you have not yet taken the course on Matrices and Linear Algebra yet, do not worry. For our purposes we will consider a matrix to simply be a two dimensional array. You may consider the number of columns to be our main array. Our rows will be represented as arrays held within each column. After this has been considered, adding one matrix to the other is simple.

Use these two arrays as the variables in your code, or you may use your own if you wish:
int M1[3][3] = {{1,2,3},{4,5,6},{7,8,9}};
int M2[3][3] = {{9,8,7},{6,5,4},{3,2,1}};

 

SideSectionTitle

float
Taken from http://www.flickr.com/photos/daniello/565304023/

An image or By Students section

Solution

The solution...

Code

SolutionCode goes here. Please DO NOT put your code in <pre> tags!

Back to the Program-A-Day homepage