-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAddSubProduct.c
More file actions
84 lines (78 loc) · 1.96 KB
/
AddSubProduct.c
File metadata and controls
84 lines (78 loc) · 1.96 KB
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
#include <stdio.h>
//#include "A2Matrix.h"
int addition(double matrix1[30][30], double matrix2[30][30], int R1, int C1, int R2, int C2, double matrix3[30][30])
{
//take addition of two matrices
int i, j;
if (R1 == R1 && C1 == C2)
{
for (i = 1; i <= R1; i++)
for (j = 1; j <= C1; j++)
{
matrix3[i][j] = matrix1[i][j] + matrix2[i][j];
}
return 1;
}
else
{
printf("Error code: 100111\nDimension Error!!!");
return 100111;
}
}
int subtraction(double matrix1[30][30], double matrix2[30][30], int R1, int C1, int R2, int C2, double matrix3[30][30])
{
//take subtraction of two matrices
int i, j;
if (R1 == R1 && C1 == C2)
{
for (i = 1; i <= R1; i++)
for (j = 1; j <= C1; j++)
{
matrix3[i][j] = matrix1[i][j] - matrix2[i][j];
}
return 1;
}
else
{
printf("Error code: 100111\nDimension Error!!!");
return 100111;
}
}
int matrix_multiply(double matrix1[30][30], double matrix2[30][30], int R1, int C1, int R2, int C2, double matrix3[30][30])
{
//take product of two matrices
int i, j, r;
double sum;
if (C1 == R2)
{
for (i = 1; i <= R1; i++)
{
for (j = 1; j <= C2; j++)
{
sum = 0;
for (r = 1; r <= R1; r++)
{
sum += matrix1[i][r] * matrix2[r][j];
}
matrix3[i][j] = sum;
}
}
return 1;
}
else
{
printf("Error code: 100111\nDimension Error!!!");
return 100111;
}
}
int scalar_multiply(double K, double matrix[30][30], int R, int C, double ans[30][30])
{
//take product a matrix and a number ans=K*matrix
int i, j;
for (i = 1; i <= R; i++)
for (j = 1; j <= C; j++)
{
ans[i][j] = K * matrix[i][j];
}
return 1;
}