Created
April 29, 2012 23:46
-
-
Save kdmkdmkdm/2554078 to your computer and use it in GitHub Desktop.
matrixadditiongood
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // matrixAddition | |
| #include "stdafx.h" | |
| #include <iostream> | |
| using namespace std; | |
| int main() | |
| { | |
| int matrixA[2][3] = | |
| { | |
| {-5, 2, 8}, | |
| {1, 0, 0} | |
| }; | |
| // I would like my output to be in the format of: | |
| // A = | |
| // -5 2 8 | |
| // 1 0 0 | |
| // Loop over rows. | |
| cout << "A =" << endl; | |
| for(int i = 0; i < 2; ++i) | |
| { | |
| // Loop over columns. | |
| for(int j = 0; j < 3; ++j) | |
| { | |
| cout << matrixA[i][j] << " "; | |
| } | |
| cout << endl; | |
| } | |
| cout << endl; | |
| int matrixB[2][3] = | |
| { | |
| {1, 0, 2}, | |
| {0, 3, -6} | |
| }; | |
| // I would like my output to be in the format of: | |
| // B = | |
| // 1 0 2 | |
| // 0 3 -6 | |
| // Loop over rows. | |
| cout << "B =" << endl; | |
| for(int i = 0; i < 2; ++i) | |
| { | |
| // Loop over columns. | |
| for(int j = 0; j < 3; ++j) | |
| { | |
| cout << matrixB[i][j] << " "; | |
| } | |
| cout << endl; | |
| } | |
| cout << endl; | |
| // A + B = | |
| cout << "A + B =" << endl; | |
| int sum[2][3]; | |
| for(int i = 0; i < 2; ++i) | |
| { | |
| // Loop over columns. | |
| for(int j = 0; j < 3; ++j) | |
| { | |
| sum[i][j] = matrixA[i][j] + matrixB[i][j]; | |
| cout << sum[i][j] << " "; | |
| } | |
| cout << endl; | |
| } | |
| cout << endl; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment