-
-
Save AlexandruFilipescu/f140769dd5cd067f660b81befa0b7b11 to your computer and use it in GitHub Desktop.
C++ Prof Constantinescu Matrice inmultita(Matrix multiplication)
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> | |
using namespace std; | |
int main() { | |
int *q, *p, *r, k,y,l,c,total, matrice[100][100]; | |
cout << "Introduceti liniile si coloanele matricelor: "; | |
cin >> l >> c; | |
total = l * c; | |
q = new int(total); | |
p = new int(total); | |
r = new int(total); | |
cout << "Introduceti elementele matricii 1: " << endl; | |
for (int i = 0; i < total; i++) { | |
cin >> q[i]; | |
} | |
cout << "Introduceti elementele matricii 2: " << endl; | |
for (int i = 0; i < l; i++) { | |
for (int j = 0; j < c; j++) { | |
cin >> matrice[i][j]; | |
} | |
} | |
k = 0; | |
for (int i = 0; i < l; i++) { | |
for (int j = 0; j < c; j++) { | |
p[k] = matrice[j][i]; | |
k++; | |
} | |
} | |
k = 0; | |
y = 0; | |
for (int i = 0; i < total; i++) { | |
if (i < sqrt(total)) { | |
k = 0; | |
} | |
else { | |
k = 2; | |
} | |
if (i%2==0) { | |
y = 0; | |
} else { | |
y = 2; | |
} | |
r[i] = q[k] * p[y]; | |
} | |
k = 0; | |
y = 0; | |
for (int i = 0; i < total; i++) { | |
if (i < sqrt(total)) { | |
k = 1; | |
} else { | |
k = 3; | |
} | |
if (i%2==0) { | |
y = 1; | |
} else { | |
y = 3; | |
} | |
r[i] += q[k] * p[y]; | |
} | |
for (int i = 0; i < total; i++) | |
{ | |
cout << r[i] << " "; | |
} | |
system("pause"); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment