-
Notifications
You must be signed in to change notification settings - Fork 0
/
matrixmath.c
81 lines (65 loc) · 1.41 KB
/
matrixmath.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
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <stdlib.h>
int main()
{
printf("Matrix Calculator\n");
printf("Enter Values for Matrix A:\n");
int matrixA[2][2];
for (int i = 0; i < 2; ++i)
for (int j = 0; j < 2; ++j)
scanf("%d", &matrixA[i][j]);
printf("Enter Values for Matrix B:\n");
int matrixB[2][2];
for (int i = 0; i < 2; ++i)
for (int j = 0; j < 2; ++j)
scanf("%d", &matrixB[i][j]);
printf("\n");
printf("Addition\n");
for (int i = 0; i < 2; ++i)
{
for (int j = 0; j < 2; ++j)
printf("%d\t", matrixA[i][j] + matrixB[i][j]);
printf("\n");
}
printf("Substraction\n");
for (int i = 0; i < 2; ++i)
{
for (int j = 0; j < 2; ++j)
printf("%d\t", matrixA[i][j] - matrixB[i][j]);
printf("\n");
}
int result[2][2];
for (int i = 0; i < 2; i++)
for (int j = 0; j < 2; j++)
{
result[i][j] = 0;
for (int k = 0; k < 2; k++)
result[i][j] += matrixA[i][k] * matrixB[k][j];
}
printf("Multiplication\n");
for (int i = 0; i < 2; ++i)
{
for (int j = 0; j < 2; ++j)
printf("%d\t", result[i][j]);
printf("\n");
}
for (int i = 0; i < 2; i++)
{
for (int j = 0; j < 2; j++)
{
result[i][j] = 0;
for (int k = 0; k < 2; k++)
result[i][j] += matrixA[i][k] / matrixB[k][j];
}
}
printf("Division\n");
for (int i = 0; i < 2; ++i)
{
for (int j = 0; j < 2; ++j)
printf("%d\t", result[i][j]);
printf("\n");
}
system("pause>nil");
return 0;
}