-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathMatrix multiply.c
More file actions
31 lines (30 loc) · 852 Bytes
/
Matrix multiply.c
File metadata and controls
31 lines (30 loc) · 852 Bytes
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
#include <stdio.h>
int main() {
int a[10][10], b[10][10], mul[10][10], r, c, i, j, k;
printf("Enter the number of rows and columns: ");
scanf("%d %d", &r, &c);
printf("Enter elements of first matrix:\n");
for(i = 0; i < r; i++) {
for(j = 0; j < c; j++) {
scanf("%d", &a[i][j]);
}
}
printf("Enter elements of second matrix:\n");
for(i = 0; i < r; i++) {
for(j = 0; j < c; j++) {
scanf("%d", &b[i][j]);
}
}
printf("Product of the matrices:\n");
for(i = 0; i < r; i++) {
for(j = 0; j < c; j++) {
mul[i][j] = 0;
for(k = 0; k < c; k++) {
mul[i][j] += a[i][k] * b[k][j];
}
printf("%d\t", mul[i][j]);
}
printf("\n");
}
return 0;
}