-
Notifications
You must be signed in to change notification settings - Fork 73
/
bochvaroska_ekaterina_problem10.c
104 lines (92 loc) · 1.82 KB
/
bochvaroska_ekaterina_problem10.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
96
97
98
99
100
101
102
103
104
#include<stdio.h>
int main(){
//declaring some values
int dMatrix1[10][10];
int dMatrix2[10][10];
int R1;
int C1;
int R2=C1;
int C2=R1;
//asking user for an input
printf("\nEnter two positive numbers R and C:");
scanf("%d",&R1);
scanf("%d",&C1);
if(C1==R2)
{
//entering the elements of the first matrix:
printf("\nEnter some values for the first matrix:");
for(int i=1;i<=R1;i++)
{
for(int j=1;j<=C1;j++)
{
printf("\nEnter element e[%d][%d]:", i, j);
scanf("%d ", &dMatrix1[i][j]);
}
}
//printing the elements of the first matrix:
printf("\nEntered first matrix:\n");
for(int i=0;i<R1;i++)
{
for(int j=0;j<C1;j++)
{
printf("%d ", dMatrix1[i][j]); //printing the element
if(j==R1)
{
printf("\n");
}
}
}
//entering the elements of the second matrix:
printf("\nEnter some values for the second matrix:");
for(int i=0;i<R2;i++)
{
for(int j=0;j<C2;j++)
{
printf("\nEnter element e[%d][%d]:", i, j);
scanf("%d ", &dMatrix2[i][j]);
}
}
//printing the elements of the second matrix:
printf("\nEntered second matrix:\n");
for(int i=1;i<=R2;i++)
{
for(int j=1;j<=C2;j++)
{
printf("%d ",dMatrix2[i][j]); //printing the element
if(j==R2)
{
printf("\n");
}
}
}
//bulding the third matrix
int dMatrix3[R1][C2];
int sum=0;
printf("The multiplication of the matrices is:");
for(int i=0;i<R1;i++){
for(int j=0;j<C2;j++)
{
for(int k=0;k<R2;k++){
sum=+dMatrix1[i][k]*dMatrix2[k][j];
}
dMatrix3[i][j]=sum;
sum=0;
}
}
//printing the elements of the recieved matrix
printf("\nEntered second matrix:\n");
for(int i=0;i<R1;i++)
{
for(int j=0;j<C2;j++)
{
printf("%d ",dMatrix3[i][j]); //printing the element
}//endfor
printf("\n");
}//endfor
}
else
{
printf("\n Not possible for the given rows and columns!");
}
return 0;
}