Created
February 10, 2012 21:12
-
-
Save felladrin/1792915 to your computer and use it in GitHub Desktop.
Multiplicação de matrizes usando a classe Vector
This file contains 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
#include <iostream> | |
#include <iomanip> | |
#include <vector> | |
using namespace std; | |
void altera(vector< vector<int> > & v, int i, int j, int x); | |
int main() | |
{ | |
vector< vector<int> > a(2, vector<int>(3)); | |
vector< vector<int> > b(3, vector<int>(4)); | |
vector< vector<int> > c(2, vector<int>(4)); | |
for (int i = 0; i < 2; i++) | |
{ | |
for (int j = 0; j < 3; j++) | |
{ | |
int x; | |
cin >> x; | |
altera(a, i, j, x); | |
} | |
} | |
for (int i = 0; i < 3; i++) | |
{ | |
for (int j = 0; j < 4; j++) | |
{ | |
int x; | |
cin >> x; | |
altera(b, i, j, x); | |
} | |
} | |
for (int i = 0; i < 2; i++) | |
{ | |
for (int j = 0; j < 4; j++) | |
{ | |
c[i][j] = 0; | |
for (int k = 0; k < 3; k++) | |
c[i][j] += a[i][k] * b[k][j]; | |
} | |
} | |
for (int i = 0; i < 2; i++) | |
{ | |
for (int j = 0; j < 4; j++) | |
{ | |
if (j == 0) | |
cout << setw(4) << c[i][j]; | |
else | |
cout << setw(5) << c[i][j]; | |
} | |
cout << endl; | |
} | |
return 0; | |
} | |
void altera(vector< vector<int> > & v, int i, int j, int x) | |
{ | |
v[i][j] = x; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment