-
Notifications
You must be signed in to change notification settings - Fork 0
/
pointers11.c
58 lines (50 loc) · 1.22 KB
/
pointers11.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
#include <stdio.h>
void multiplyMatrices(int *matrix1, int *matrix2, int *result)
{
for (int i = 0; i < 3; i++)
{
for (int j = 0; j < 3; j++)
{
*(result + i * 3 + j) = 0;
for (int k = 0; k < 3; k++)
{
*(result + i * 3 + j) += *(matrix1 + i * 3 + k) * *(matrix2 + k * 3 + j);
}
}
}
}
void displayMatrix(int *matrix)
{
for (int i = 0; i < 3; i++)
{
for (int j = 0; j < 3; j++)
{
printf("%d ", *(matrix + i * 3 + j));
}
printf("\n");
}
}
int main()
{
int matrix1[3][3], matrix2[3][3], result[3][3];
printf("enter the elements of matrix 1:\n");
for (int i = 0; i < 3; i++)
{
for (int j = 0; j < 3; j++)
{
scanf("%d", &matrix1[i][j]);
}
}
printf("enter the elements of matrix 2:\n");
for (int i = 0; i < 3; i++)
{
for (int j = 0; j < 3; j++)
{
scanf("%d", &matrix2[i][j]);
}
}
multiplyMatrices((int *)matrix1, (int *)matrix2, (int *)result);
printf("\nresult :\n");
displayMatrix((int *)result);
return 0;
}