-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.c
75 lines (74 loc) · 1.7 KB
/
main.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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#include <stdio.h>
#include <conio.h>
void main()
{
int m1,n1,m2,n2;
printf("Enter the number of rows of the first matrix: \n");
scanf("%d",&m1);
printf("Enter the number of columns of the first matrix: \n");
scanf("%d",&n1);
int a[m1][n1];
printf("Enter elements of the first matrix: \n");
for(int i=0;i<m1;i++)
{
for(int j=0;j<n1;j++)
{
scanf("%d",&a[i][j]);
}
}
printf("Elements of the first matrix are: \n");
for(int i=0;i<m1;i++)
{
for(int j=0;j<n1;j++)
{
printf("%4d",a[i][j]);
}
printf("\n");
}
printf("Enter the number of rows of the second matrix: \n");
scanf("%d",&m2);
printf("Enter the number of columns of the second matrix: \n");
scanf("%d",&n2);
int b[m2][n2];
printf("Enter elements of the second matrix: \n");
for(int i=0;i<m2;i++)
{
for(int j=0;j<n2;j++)
{
scanf("%d",&b[i][j]);
}
}
printf("Elements of the second matrix are: \n");
for(int i=0;i<m2;i++)
{
for(int j=0;j<n2;j++)
{
printf("%4d",b[i][j]);
}
printf("\n");
}
printf("Elements of the third matrix containing the product of first and second matrix are: \n");
int m3,n3;
m3=m1;
n3=n2;
int c[m3][n3];
for(int i=0;i<m3;i++)
{
for(int j=0;j<n3;j++)
{
c[i][j]=0;
for(int k=0;k<n1;k++)
{
c[i][j] = c[i][j] + a[i][k] * b[k][j];
}
}
}
for(int i=0;i<m3;i++)
{
for(int j=0;j<n3;j++)
{
printf("%8d",c[i][j]);
}
printf("\n");
}
}