-
Notifications
You must be signed in to change notification settings - Fork 0
/
matrix multiplication.c
95 lines (92 loc) · 1.48 KB
/
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
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
#include<stdio.h>
#include<stdio.h>
void read(int (*arr)[100],int (*arr1)[100],int a,int b,int c,int d)
{
printf("ENTER THE ELEMENTS OF AN ARRAY\n");
for(int i=0;i<a;i++)
{
for(int j=0;j<b;j++)
{
scanf("%d",((*arr+i)+j));
}
}
for(int i=0;i<c;i++)
{
for(int j=0;j<d;j++)
{
scanf("%d",((*arr1+i)+j));
}
}
}
void display(int (*arr)[100],int (*arr1)[100],int a,int b,int c,int d)
{
for(int i=0;i<a;i++)
{
for(int j=0;j<b;j++)
{
printf("%d\t",((*arr+i)+j));
}
printf("\n");
}
for(int i=0;i<c;i++)
{
for(int j=0;j<d;j++)
{
printf("%d\t",((*arr1+i)+j));
}
printf("\n");
}
}
void display1(int (*arr2)[100],int a,int d)
{ printf("MULTIFIED ARRAY IS \n");
for(int i=0;i<a;i++)
{
for(int j=0;j<d;j++)
{
printf("%d\t",((arr2+i)+j));
}
printf("\n");
}
}
void mul(int (*arr)[100],int (*arr1)[100],int a,int b,int c)
{
int arr2[a][100],sum=0;
int (*q)[100];
q=arr2;
for(int i=0;i<a;i++)
{
for(int j=0;j<b;j++)
{
for(int k=0;k<c;k++)
{
sum += (((*arr[i] + i) + k)) * (((*arr2[i] + k) + j));
}
sum=((arr2+i)+j);
sum=0;
}
}
display1(q,a,b);
}
int main()
{
int a,b,c,d;
printf("ENTER THE ROWS AND COLOUMN OF ARRAY 1\n");
scanf("%d%d",&a,&b);
printf("ENTER THE ROWS AND COLOUMN OF ARRAY 2\n");
scanf("%d%d",&c,&d);
int arr[a][b];
int arr1[c][d];
int (*p)[100];
int (*p1)[100];
p=arr;
p1=arr1;
if(b==c)
{
read(p,p1,a,b,c,d);
display(p,p1,a,b,c,d);
mul(p,p1,a,d,c);
}
else
printf("CANNOT MULTIPLY THE GIVEN TWO ARRAYS\n");
return 0;
}