-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMatrix_multiplication.c
More file actions
87 lines (84 loc) · 2 KB
/
Matrix_multiplication.c
File metadata and controls
87 lines (84 loc) · 2 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
87
#include <stdio.h>
#include <string.h>
int main ()
{
int m,n,i,j,k;
printf(" MATRIX MULTIPLICATION \n");
printf("Enter the no. of rows for Matrix A :");
scanf("%d",&m);
printf("Enter the no. of columns for Matrix A :");
scanf("%d",&n);
int arr[m][n];
printf(" \nmow enter the elements\n ");
for ( i = 0; i < m; i++)
{
for (j = 0; j < n; j++)
{
printf("A[%d][%d] = ",i,j);
scanf("%d",&arr[i][j]);
}
}
printf(" MATRIX A \n");
for ( i = 0; i < m; i++)
{
for (j = 0; j < n; j++)
{
printf(" %d ",arr[i][j]);
}
printf("\n");
}
printf("Now lets enter the elememnts of Matrix B\n");
int p,q;
printf("Enter the no. of rows for Matrix B :");
scanf("%d",&p);
printf("Enter the no. columns of Matrix B :");
scanf("%d",&q);
int brr[p][q];
printf(" \nmow enter the elements\n ");
for ( i = 0; i < p; i++)
{
for (j = 0; j < q; j++)
{
printf("B[%d][%d] = ",i,j);
scanf("%d",&brr[i][j]);
}
}
printf(" MATRIX B \n");
for ( i = 0; i < p; i++)
{
for (j = 0; j < q; j++)
{
printf(" %d ",brr[i][j]);
}
printf("\n");
}
if(m == q)
{
printf(" The resultant matrix \n");
int crr[m][q];
for ( i = 0; i < m; i++)
{
for(j = 0; j < q; j++)
{
crr[i][j] = 0;
for(k = 0; k < q; k++)
{
crr[i][j] = crr[i][j] + arr[i][k] * brr[k][j];
}
}
}
for(i = 0; i < m; i++)
{
for(j = 0; j < q; j++)
{
printf(" %d ",crr[i][j]);
}
printf("\n");
}
}
else
{
printf(" the multiplication is not possible invalid input of row and column");
}
return 0;
}