forked from Kornpituk/Week_7
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathArrayMatrix.cpp
More file actions
97 lines (83 loc) · 2.83 KB
/
Copy pathArrayMatrix.cpp
File metadata and controls
97 lines (83 loc) · 2.83 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
85
86
87
88
89
90
91
92
93
94
95
96
97
#include<stdio.h>
void InputAandB(int Array1[3][3],int Array2[3][3],int Array3[3][3]){
printf("--------------------- Input Matrix A -----------------------\n");
for(int i=0;i<3;i++){
for(int j=0;j<3;j++){
printf("MatA[%d][%d]: ",i,j);
scanf("%d",&Array1[i][j]);
}
}
printf("--------------------- Input Matrix A -----------------------\n");
for(int i=0;i<3;i++){
for(int j=0;j<3;j++){
printf("MatB[%d][%d]: ",i,j);
scanf("%d",&Array2[i][j]);
}
}
}
void PrintAandB(int Array1[3][3],int Array2[3][3],int Array3[3][3]){
printf("--------------------- Matrix A -----------------------\n");
for(int i=0;i<3;i++){
for(int j=0;j<3;j++){
printf("%d ",Array1[i][j]);
}
printf("\n");
}
printf("--------------------- Matrix B -----------------------\n");
for(int i=0;i<3;i++){
for(int j=0;j<3;j++){
printf("%d ",Array2[i][j]);
}
printf("\n");
}
}
void Positive(int Array1[3][3],int Array2[3][3],int Array3[3][3]){
for(int i=0;i<3;i++){
for(int j=0;j<3;j++){
Array3[i][j]=Array1[i][j]+Array2[i][j];
}
}
}
void Negative(int Array1[3][3],int Array2[3][3],int Array3[3][3]){
for(int i=0;i<3;i++){
for(int j=0;j<3;j++){
Array3[i][j]=Array1[i][j]-Array2[i][j];
}
}
}
void PrintAns(int Array3[3][3]){
for(int i=0;i<3;i++){
for(int j=0;j<3;j++){
printf("%d ",Array3[i][j]);
}
printf("\n");
}
}
int main(){
int Array1[3][3],Array2[3][3],Array3[3][3];
int Case;
printf("Case1 PlusMatrix()\n");
printf("Case2 MinusMatrix()\n");
printf("Please Enter Case: ");
scanf("%d",&Case);
switch(Case){
case 1 ://-----------------------------------------------------------------------------------------------
printf("[You Select Case1 PlusMatrix]\n");
InputAandB(Array1,Array2,Array3);
PrintAandB(Array1,Array2,Array3);
Positive(Array1,Array2,Array3);
printf("--------------------- positive Matrix A-B -----------------------\n");
PrintAns(Array3);
break;
case 2 ://-------------------------------------------------------------------------------------------------
printf("[You Select Case2 MinusMatrix]\n");
InputAandB(Array1,Array2,Array3);
PrintAandB(Array1,Array2,Array3);
Negative(Array1,Array2,Array3);
printf("--------------------- Negative Matrix A-B -----------------------\n");
PrintAns(Array3);
break;
default:
printf("[[ProGrams Error!!!]]\n");
}
}