-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmatrix operations.c
85 lines (84 loc) · 1.59 KB
/
matrix operations.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
/*matrix operations with functions arrays and arrays passing and things just are too old i guess!?*/
#include <stdio.h>
#define rows 3
#define cols 4
char op;
int matrix_1[rows][cols], matrix_2[rows][cols], matrix_3[rows][cols];
int Operations() ;
int main()
{
printf("\nthis program will do a user specified operation on two [%d by %d] user inputed matrixes\n\n", rows, cols);
for (int i = 0; i < rows; ++i)
{
for (int j = 0; j < cols; ++j)
{
printf("enter the first matrix values: ");
scanf("%d", &matrix_1[i][j]);
}
}
printf("\n\n");
for (int x = 0; x < rows; ++x)
{
for (int y = 0; y < cols; ++y)
{
printf("enter the second matrix values values: ");
scanf("%d", &matrix_2[x][y]);
}
}
printf("Enter operator: ");
scanf("%s", &op);
Operations();
printf("the result is:\n");
for (int i = 0; i < rows; ++i)
{
for (int j = 0; j < cols; ++j)
{
printf("%d ", matrix_3[i][j]);
}
printf("\n");
}
return 0;
}
int Operations()
{
if (op == '+')
{
for (int i = 0; i < rows; ++i)
{
for (int j = 0; j < cols; ++j)
{
matrix_3[i][j] = matrix_1[i][j] + matrix_2[i][j];
}
}
}
else if (op == '-')
{
for (int i = 0; i < rows; ++i)
{
for (int j = 0; j < cols; ++j)
{
matrix_3[i][j] = matrix_1[i][j] - matrix_2[i][j];
}
}
}
else if (op == '*')
{
for (int i = 0; i < rows; ++i)
{
for (int j = 0; j < cols; ++j)
{
matrix_3[i][j] = matrix_1[i][j] * matrix_2[i][j];
}
}
}
if (op == '/')
{
for (int i = 0; i < rows; ++i)
{
for (int j = 0; j < cols; ++j)
{
matrix_3[i][j] = matrix_1[i][j] / matrix_2[i][j];
}
}
}
}