Difference between revisions of "Adding Two Matrices"
ChristopherJ (Talk | contribs) |
ChristopherJ (Talk | contribs) |
||
Line 6: | Line 6: | ||
int M1[3][3] = {{1,2,3},{4,5,6},{7,8,9}};<BR> | 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}};<BR> | int M2[3][3] = {{9,8,7},{6,5,4},{3,2,1}};<BR> | ||
+ | |||
+ | To add one matrix to the other you simply add each corresponding number on the first matrix to the one on the second. For example, I take the number in the first row, and the first column, and add it to the number in the first row and the first column in the second matrix. Once I have done this for each number in both matrices, the resulting matrix will be our answer. | ||
|SideSection= | |SideSection= |
Revision as of 11:02, 1 April 2010
Back to the Program-A-Day homepage
ProblemTo 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: To add one matrix to the other you simply add each corresponding number on the first matrix to the one on the second. For example, I take the number in the first row, and the first column, and add it to the number in the first row and the first column in the second matrix. Once I have done this for each number in both matrices, the resulting matrix will be our answer. |
SideSectionTitle
An image or By Students section | |
---|---|---|
SolutionThe solution... | ||
CodeSolutionCode goes here. Please DO NOT put your code in <pre> tags! |