-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathprodusM1.c
46 lines (38 loc) · 1016 Bytes
/
produsM1.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#include<stdio.h>
int main()
{
// citire
int a[20][20], b[20][20], rez[20][20];
int n1, m1, n2, m2;
int i, j, k;
scanf("%d%d", &n1, &m1);
for(i = 0;i < n1;i ++)
for(j = 0;j < m1;j ++) {
scanf("%d", &a[i][j]);
a[i][j] = 0;
}
scanf("%d%d", &n2, &m2);
for(i = 0;i < n2;i ++)
for(j = 0;j < m2;j ++){
scanf("%d", &b[i][j]);
b[i][j] = 0;
}
// verificare dimensiune
if(m1 != n2) {
printf("matricele nu pot fi inmultite!");
return 0;
}
// inmultire a doua matrici
for(i = 0;i < n1;i ++)
for(j = 0; j < m1;j ++)
for(k = 0; k < m2; k ++)
rez[i][j] += a[i][j] * b[j][k];
// afisare matrice rezultat
printf("Matricea rezultat este: \n");
for(i = 0;i < n1;i ++)
{
for(j = 0;j <= m2;j ++)
printf("%d ", rez[i][j]);
printf("\n");
}
}