Skip to content

Instantly share code, notes, and snippets.

@AlexandruFilipescu
Last active June 9, 2019 16:57
Show Gist options
  • Save AlexandruFilipescu/f140769dd5cd067f660b81befa0b7b11 to your computer and use it in GitHub Desktop.
Save AlexandruFilipescu/f140769dd5cd067f660b81befa0b7b11 to your computer and use it in GitHub Desktop.
C++ Prof Constantinescu Matrice inmultita(Matrix multiplication)
#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