forked from Nivedpv2004/C-PROGRAMING
-
Notifications
You must be signed in to change notification settings - Fork 0
/
matrix_multiplication.c
48 lines (48 loc) · 952 Bytes
/
matrix_multiplication.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
#include<stdio.h>
int main()
{
int n;
printf("Enter the size of the matrix: ");
scanf("%d",&n);
int a[n][n],b[n][n];
printf("Enter the elements of the first matrix: ");
for(int i=0;i<n;i++)
{
for(int j=0;j<n;j++)
{
scanf("%d",&a[i][j]);
}
}
printf("Enter the elements of the second matrix: ");
for(int i=0;i<n;i++)
{
for(int j=0;j<n;j++)
{
scanf("%d",&b[i][j]);
}
}
int s=0;
int c[n][n];
for(int i=0;i<n;i++)
{
for(int j=0;j<n;j++)
{
for(int k=0;k<n;k++)
{
s=s+a[i][k]*b[k][j];
}
c[i][j]=s;
s=0;
}
}
printf("The product of the two matrices is: \n");
for(int i=0;i<n;i++)
{
for(int j=0;j<n;j++)
{
printf("%d ",c[i][j]);
}
printf("\n");
}
return 0;
}