-
Notifications
You must be signed in to change notification settings - Fork 0
/
twodarray2.c
93 lines (86 loc) · 2.08 KB
/
twodarray2.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
#include<stdio.h>
int main(int argc, char const *argv[])
{
int first[10] [10],second[10][10],result[10][10],r1,r2,c1,c2,i,j,k,sum=0;
printf("Enter rows & colum for first matrix : ");
scanf("%d %d",&r1,&c1);
printf("Enter rows & colum for second matrix : ");
scanf("%d %d",&r2,&c2);
while (c1!=r2)
{
printf("Error !! colum of first matrix not equal to second matrix");
printf("Enter rows & colum for first matrix : ");
scanf("%d %d",&r1,&c1);
printf("Enter rows & colum for second matrix : ");
scanf("%d %d",&r2,&c2);
}
//takin input first matrix
printf("\nenter eliment of first matrix :\n ");
for(i=0; i<r1; i++)
{
for(j=0; j<c1; j++)
{
printf("first[%d][%d]= ",i,j);
scanf("%d",&first[i] [j]);
}
printf("\n");
}
//takin input second matrix
printf("\nenter eliment of second matrix :\n");
for(i=0; i<r2; i++)
{
for(j=0; j<c2; j++)
{
printf("second[%d][%d]= ",i,j);
scanf("%d",&second[i] [j]);
}
printf("\n");
}
//print first matrix
printf("\nfirst= ");
for(i=0; i<r1; i++)
{
printf("\t");
for(j=0; j<c1; j++)
{
printf("%d ",first[i] [j]);
}
printf("\n");
}
//print second matrix
printf("\nsecond= ");
for(i=0; i<r2; i++)
{
printf("\t");
for(j=0; j<c2; j++)
{
printf("%d ",second[i] [j]);
}
printf("\n");
}
//multiplication matrix
for(i=0; i<r1; i++)
{
for ( j = 0; j < c2; j++)
{
for ( k = 0; k < c1; k++)
{
sum=sum+first[i][k]*second[k][j];
}
result[i][j]=sum;
sum=0;
}
}
//print result matrix
printf("\nresult= ");
for(i=0; i<r1; i++)
{
printf("\t");
for(j=0; j<c2; j++)
{
printf("%d ",result[i] [j]);
}
printf("\n");
}
return 0;
}