-
Notifications
You must be signed in to change notification settings - Fork 2
/
matrix_multipication.c
56 lines (53 loc) · 1.16 KB
/
matrix_multipication.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
52
53
54
55
#include<stdio.h>
#include<conio.h>
int main()
{
int r1,c1,r2,c2;
printf("enter the no. of rows and column of first array ");
scanf("%d %d",&r1,&c1);
printf("enter the no. of rows and column of second array ");
scanf("%d %d",&r2,&c2);
if( c1!=r2)
{
printf("this multiplication is not possible");
return 0;
}
int x[r1][c1],y[r2][c2],z[r1][c2];
printf("enter the elements of first array ");
for(int i=0;i<r1;i++)
{
for(int j=0;j<c1;j++)
{
scanf("%d",&x[i][j]);
}
}
printf("enter the elements of second array ");
for(int i=0;i<r1;i++)
{
for(int j=0;j<c1;j++)
{
scanf("%d",&y[i][j]);
}
}
for(int i=0;i<r1;i++)
{
for(int j=0;j<c2;j++)
{
z[i][j]=0;
for(int k=0;k<c1;k++)
{
z[i][j]=z[i][j]+(x[i][k]*y[k][j]);
}
}
}
printf("the matrix after multiplication is ");
for(int i=0;i<r1;i++)
{
for(int j=0;j<c2;j++)
{
printf("%d %s",&z[i][j],' ');
}
printf("\n");
}
return 0;
}