Skip to content

Instantly share code, notes, and snippets.

@frzleaf
Created November 11, 2015 11:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save frzleaf/452ad7f82c6d0676a1e9 to your computer and use it in GitHub Desktop.
Save frzleaf/452ad7f82c6d0676a1e9 to your computer and use it in GitHub Desktop.
/*
* Bai 4.17: Nhan hai ma tran
* Le Quang Thanh - 11020287
*/
#include <iostream>
using namespace std;
int main(){
int m,n,k;
cout << "Ma tran thu 1 - mxn = :";
cin >> m >> n;
cout << "Ma tran thu 2 - k = :";
cin >> k;
double a[m][n], b[n][k], c[m][k];
for ( int i = 0; i < m ; ++i ){
for (int j = 0; j < n; ++j ){
a[i][j] = i*j;
}
}
for ( int i = 0; i < n ; ++i ){
for (int j = 0; j < k; ++j ){
b[i][j] = i*j;
}
}
for ( int i = 0; i < n; ++i ){
for ( int j = 0; j < k ; ++j ){
c[i][j] = 0;
}
}
for ( int i = 0 ; i < m ; ++i ){
for ( int j = 0; j < n ; ++j ){
for ( int t = 0; t < k ; ++t){
c[i][t] += a[i][j]*b[j][t];
}
}
}
for ( int i = 0; i < m; ++i ){
for ( int j = 0; j < k ; ++j ){
cout << c[i][j] << " ";
}
cout << endl;
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment