forked from itsprueba/Hacktoberfest
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathmatrixMultiplication.c
More file actions
86 lines (77 loc) · 2.04 KB
/
matrixMultiplication.c
File metadata and controls
86 lines (77 loc) · 2.04 KB
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#include <stdio.h>
void main()
{
int array1[100][100], array2[100][100], mult[100][100], i, j, r1, c1, r2, c2;
printf("Enter the no. of rows of matrix 'A' : \n");
scanf("%d", &r1);
printf("Enter the no. of columns of matrix 'A' : \n");
scanf("%d", &c1);
printf("Enter the no. of rows of matrix 'B' : \n");
scanf("%d", &r2);
printf("Enter the no. of columns of matrix 'B' : \n");
scanf("%d", &c2);
for (i = 0; i < r1; i++)
{
for (j = 0; j < c1; j++)
{
printf("Enter the elements of the matrix 'A' : \n");
scanf("%d", &array1[i][j]);
}
}
for (i = 0; i < r2; i++)
{
for (j = 0; j < c2; j++)
{
printf("Enter the elements of the matrix 'B' : \n");
scanf("%d", &array2[i][j]);
}
}
printf("The entered matrix A is :\n");
for(i=0;i < r1;i++)
{
for ( j = 0; j < c1; j++)
{
printf("%d\t",array1[i][j]);
}
printf("\n");
}
printf("The entered matrix B is :\n");
for(i=0;i < r2;i++)
{
for ( j = 0; j < c2; j++)
{
printf("%d\t",array2[i][j]);
}
printf("\n");
}
if (c1==r2)
{
for ( i = 0; i < r2; i++)
{
for ( j = 0; j < c1; j++)
{
mult[i][j] = (array1[i][j]*array2[j][i]);
}
}
printf("The mult is :\n");
for(i=0;i < r2;i++)
{
for ( j = 0; j < c1; j++)
{
printf("%d\t",mult[i][j]);
}
printf("\n");
}
}
else
printf("Multiplication of the given matrices is not possible ");
// printf("The multiplication of the entered matrix is :\n");
// for (i = 0; i < r; i++)
// {
// for (j = 0; j < c; j++)
// {
// printf("%d\t", sum[i][j]);
// }
// printf("\n");
// }
}