forked from kushalsingh-00/C-Programs
-
Notifications
You must be signed in to change notification settings - Fork 1
/
arr8.c
69 lines (65 loc) · 1.46 KB
/
arr8.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
/*
-------------------------------------------------------
Name : Matrix
Author : Kushal Singh Rathore
Discription : Matrix Multiplication
-------------------------------------------------------
*/
#include<stdio.h>
#define M 50
int main()
{
int a[M][M],b[M][M],product[M][M];
int arows,acolumns,brows,bcolumns;
int sum=0;
printf("Enter the rows and column of matrix a: ");
scanf("%d %d",&arows,&acolumns);
printf("Enter the elements of matrix a:\n");
for(int i=0;i<arows;i++)
{
for(int j=0;j<acolumns;j++)
{
scanf("%d",&a[i][j]);
}
}
printf("Enter the rows and column of matrix b: ");
scanf("%d %d",&brows,&bcolumns);
if(brows!=acolumns)
{
printf("Sorry!");
}
else
{
printf("Please Enter the elements of matrix b: \n");
for(int i=0;i<brows;i++)
{
for(int j=0;j<bcolumns;j++)
{
scanf("%d",&b[i][j]);
}
}
}
printf("\n");
for(int i=0;i<arows;i++)
{
for(int j=0;j<brows;j++)
{
for(int k=0;k<brows;k++)
{
sum+=a[i][k]*b[k][j];
}
product[i][j]=sum;
sum=0;
}
}
printf("Resultant matrix\n");
for(int i=0;i<arows;i++)
{
for(int j=0;j<bcolumns;j++)
{
printf("%d ",product[i][j]);
}
printf("\n");
}
return 0;
}