回答編集履歴
3
d
test
CHANGED
@@ -88,17 +88,15 @@
|
|
88
88
|
|
89
89
|
{
|
90
90
|
|
91
|
-
|
92
|
-
|
93
91
|
for (size_t i = 0; i < mat.size(); ++i) {
|
94
92
|
|
95
93
|
for (size_t j = 0; j < mat[0].size(); ++j) {
|
96
94
|
|
97
|
-
|
95
|
+
std::cout << mat[i][j] << " ";
|
98
96
|
|
99
97
|
}
|
100
98
|
|
101
|
-
|
99
|
+
std::cout << std::endl;
|
102
100
|
|
103
101
|
}
|
104
102
|
|
@@ -130,6 +128,4 @@
|
|
130
128
|
|
131
129
|
}
|
132
130
|
|
133
|
-
|
134
|
-
|
135
131
|
```
|
2
d
test
CHANGED
@@ -61,3 +61,75 @@
|
|
61
61
|
|
62
62
|
|
63
63
|
```
|
64
|
+
|
65
|
+
|
66
|
+
|
67
|
+
## vector で書き直した例
|
68
|
+
|
69
|
+
|
70
|
+
|
71
|
+
C++ なら C の配列でなく、std::vector を使ったほうがよいでしょう。
|
72
|
+
|
73
|
+
|
74
|
+
|
75
|
+
```cpp
|
76
|
+
|
77
|
+
#include <iostream>
|
78
|
+
|
79
|
+
#include <vector>
|
80
|
+
|
81
|
+
|
82
|
+
|
83
|
+
using Mat = std::vector<std::vector<int>>;
|
84
|
+
|
85
|
+
|
86
|
+
|
87
|
+
void print_array(const Mat &mat)
|
88
|
+
|
89
|
+
{
|
90
|
+
|
91
|
+
|
92
|
+
|
93
|
+
for (size_t i = 0; i < mat.size(); ++i) {
|
94
|
+
|
95
|
+
for (size_t j = 0; j < mat[0].size(); ++j) {
|
96
|
+
|
97
|
+
printf("%d ", mat[i][j]);
|
98
|
+
|
99
|
+
}
|
100
|
+
|
101
|
+
printf("\n");
|
102
|
+
|
103
|
+
}
|
104
|
+
|
105
|
+
}
|
106
|
+
|
107
|
+
|
108
|
+
|
109
|
+
int main()
|
110
|
+
|
111
|
+
{
|
112
|
+
|
113
|
+
Mat mat{
|
114
|
+
|
115
|
+
{1, 2, 3},
|
116
|
+
|
117
|
+
{4, 5, 6},
|
118
|
+
|
119
|
+
{7, 8, 9},
|
120
|
+
|
121
|
+
};
|
122
|
+
|
123
|
+
|
124
|
+
|
125
|
+
print_array(mat);
|
126
|
+
|
127
|
+
|
128
|
+
|
129
|
+
return 0;
|
130
|
+
|
131
|
+
}
|
132
|
+
|
133
|
+
|
134
|
+
|
135
|
+
```
|
1
e
test
CHANGED
@@ -12,15 +12,15 @@
|
|
12
12
|
|
13
13
|
|
14
14
|
|
15
|
-
void print_array(int array[][3], size_t
|
15
|
+
void print_array(int array[][3], size_t rows)
|
16
16
|
|
17
17
|
{
|
18
18
|
|
19
19
|
|
20
20
|
|
21
|
-
for (size_t i = 0; i <
|
21
|
+
for (size_t i = 0; i < rows; ++i) {
|
22
22
|
|
23
|
-
for (size_t j = 0; j <
|
23
|
+
for (size_t j = 0; j < 3; ++j) {
|
24
24
|
|
25
25
|
printf("%d ", array[i][j]);
|
26
26
|
|