回答編集履歴
2
誤字
test
CHANGED
@@ -90,7 +90,7 @@
|
|
90
90
|
|
91
91
|
追記
|
92
92
|
|
93
|
-
2x2, 3x3 の行列も
|
93
|
+
2x2, 3x3 の行列も扱えるようにしてみたものを示します。
|
94
94
|
|
95
95
|
```c
|
96
96
|
|
1
追記
test
CHANGED
@@ -85,3 +85,101 @@
|
|
85
85
|
ARRAY_SIZE は行列の列数になってます。
|
86
86
|
|
87
87
|
doub で dt1[ARRAY_SIZE][ARRAY_SIZE] のようにしているので。
|
88
|
+
|
89
|
+
|
90
|
+
|
91
|
+
追記
|
92
|
+
|
93
|
+
2x2, 3x3 の行列もあつ反るようにしてみたものを示します。
|
94
|
+
|
95
|
+
```c
|
96
|
+
|
97
|
+
#include <stdio.h>
|
98
|
+
|
99
|
+
|
100
|
+
|
101
|
+
void doub(int n, int dt1[][n], int dt2[][n], int dt3[][n]) {
|
102
|
+
|
103
|
+
for (int i = 0; i < n; i++) {
|
104
|
+
|
105
|
+
for (int j = 0; j < n; j++) {
|
106
|
+
|
107
|
+
dt3[i][j] = 0;
|
108
|
+
|
109
|
+
for (int k = 0; k < n; k++) {
|
110
|
+
|
111
|
+
dt3[i][j] += dt1[i][k] * dt2[k][j];
|
112
|
+
|
113
|
+
}
|
114
|
+
|
115
|
+
}
|
116
|
+
|
117
|
+
}
|
118
|
+
|
119
|
+
}
|
120
|
+
|
121
|
+
|
122
|
+
|
123
|
+
void show_matrix(int n, int dt[][n]) {
|
124
|
+
|
125
|
+
for (int i = 0; i < n; i++) {
|
126
|
+
|
127
|
+
for (int j = 0; j < n; j++) {
|
128
|
+
|
129
|
+
printf("%3d", dt[i][j]);
|
130
|
+
|
131
|
+
}
|
132
|
+
|
133
|
+
printf("\n");
|
134
|
+
|
135
|
+
}
|
136
|
+
|
137
|
+
}
|
138
|
+
|
139
|
+
|
140
|
+
|
141
|
+
int main(void)
|
142
|
+
|
143
|
+
{
|
144
|
+
|
145
|
+
int dt2_1[2][2] = { {1,2},{2,3} };
|
146
|
+
|
147
|
+
int dt2_2[2][2] = { {3,4},{4,5} };
|
148
|
+
|
149
|
+
int dt2_3[2][2] = { {0,0},{0,0} };
|
150
|
+
|
151
|
+
|
152
|
+
|
153
|
+
doub(2, dt2_1, dt2_2, dt2_3);
|
154
|
+
|
155
|
+
show_matrix(2, dt2_3);
|
156
|
+
|
157
|
+
printf("\n");
|
158
|
+
|
159
|
+
|
160
|
+
|
161
|
+
int dt3_1[3][3] = { {1,2,3},{2,3,0},{0,0,1} };
|
162
|
+
|
163
|
+
int dt3_2[3][3] = { {3,4,0},{4,5,0},{0,0,1} };
|
164
|
+
|
165
|
+
int dt3_3[3][3];
|
166
|
+
|
167
|
+
|
168
|
+
|
169
|
+
doub(3, dt3_1, dt3_2, dt3_3);
|
170
|
+
|
171
|
+
show_matrix(3, dt3_3);
|
172
|
+
|
173
|
+
|
174
|
+
|
175
|
+
return 0;
|
176
|
+
|
177
|
+
}
|
178
|
+
|
179
|
+
```
|
180
|
+
|
181
|
+
|
182
|
+
|
183
|
+
実行例
|
184
|
+
|
185
|
+
![イメージ説明](4d1e088e69a70bf361bccaa0b0ae64dd.png)
|