forked from Sanketwable/C_ode
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmatrixmul.c
51 lines (47 loc) · 1.01 KB
/
matrixmul.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
47
48
49
50
51
#include<stdio.h>
#include<stdlib.h>
int main()
{
int or_A, oc_A, or_B, oc_B;
printf("Enter the order of first matrix as m<space>n.\n");
scanf("%d%d", &or_A,&oc_A);
printf("Enter the order of second matrix as m<space>n.\n");
scanf("%d%d", &or_B,&oc_B);
if(oc_A!=or_B)
{
printf("These matrices cannot be multiplied.\n");
exit(0);
}
int A[or_A][oc_A], B[or_B][oc_B], C[or_A][oc_B];
for(int i=0; i<or_A; i++)
{
for(int j=0; j<oc_A; j++)
{
printf("Enter element A(%d%d) of matrix A :", i+1, j+1);
scanf("%d",&A[i][j]);
}
}
for(int i=0; i<or_B; i++)
{
for(int j=0; j<oc_B; j++)
{
printf("Enter element B(%d%d) of matrix B :",i+1,j+1);
scanf("%d",&B[i][j]);
}
}
printf("\nThe resultant matrix is.\n");
for(int i=0; i<or_A; i++)
{
for(int j=0; j<oc_B; j++)
{
C[i][j]=0;
for(int n=0; n<oc_A; n++)
{
C[i][j] = C[i][j] + A[i][n] * B[n][j];
}
printf("%d ",C[i][j]);
}
printf("\n");
}
return 0;
}