質問編集履歴

5

codeの追加

2019/11/21 04:21

投稿

hikaru_love_n
hikaru_love_n

スコア16

test CHANGED
File without changes
test CHANGED
@@ -222,8 +222,4 @@
222
222
 
223
223
  }
224
224
 
225
-
226
-
227
-
228
-
229
225
  ```

4

hファイル、mainファイルの追加

2019/11/21 04:21

投稿

hikaru_love_n
hikaru_love_n

スコア16

test CHANGED
File without changes
test CHANGED
@@ -120,116 +120,110 @@
120
120
 
121
121
 
122
122
 
123
+ main.cファイル↓
124
+
125
+ ```c
126
+
127
+ #include <stdio.h>
128
+
129
+ #include <string.h>
130
+
131
+ #include <assert.h>
132
+
133
+ #include "str_sort.h"
134
+
135
+ #define MAX_N 64
136
+
137
+
138
+
139
+
140
+
141
+ int str_array_scan(record_t a[])
142
+
143
+ {
144
+
145
+ int i;
146
+
147
+ int n;
148
+
149
+ fprintf(stderr, "n = ");
150
+
151
+ scanf("%d",&n);
152
+
153
+ assert(n<=MAX_N);
154
+
155
+ for (i=0; i<n; i++) {
156
+
157
+ fprintf(stderr, "[%d].name : ", i);
158
+
159
+ scanf(STRFMT, a[i].name);
160
+
161
+ fprintf(stderr, "[%d].age : ", i);
162
+
163
+ scanf("%d", &a[i].age);
164
+
165
+ fprintf(stderr, "[%d].height : ", i);
166
+
167
+ scanf("%lf", &a[i].height);
168
+
169
+ }
170
+
171
+ return n;
172
+
173
+ }
174
+
175
+
176
+
177
+
178
+
179
+ void str_array_print(int n, record_t a[])
180
+
181
+ {
182
+
183
+ int i;
184
+
185
+ for (i=0; i<n; i++) {
186
+
187
+ printf("%-10s", a[i].name);
188
+
189
+ printf("%3d", a[i].age);
190
+
191
+ printf("%7.2f", a[i].height);
192
+
193
+ printf("\n");
194
+
195
+ }
196
+
197
+ }
198
+
199
+
200
+
201
+
202
+
203
+ int main(void)
204
+
205
+ {
206
+
207
+ int n;
208
+
209
+ record_t a[MAX_N];
210
+
211
+
212
+
213
+ n = str_array_scan(a);
214
+
215
+ str_sort(n, a);
216
+
217
+ str_array_print(n, a);
218
+
219
+
220
+
221
+ return 0;
222
+
223
+ }
224
+
123
225
 
124
226
 
125
227
 
126
228
 
127
229
  ```
128
-
129
-
130
-
131
- str_sort_main.c```c
132
-
133
- #include <stdio.h>
134
-
135
- #include <string.h>
136
-
137
- #include <assert.h>
138
-
139
- #include "str_sort.h"
140
-
141
- #define MAX_N 64
142
-
143
-
144
-
145
-
146
-
147
- int str_array_scan(record_t a[])
148
-
149
- {
150
-
151
- int i;
152
-
153
- int n;
154
-
155
- fprintf(stderr, "n = ");
156
-
157
- scanf("%d",&n);
158
-
159
- assert(n<=MAX_N);
160
-
161
- for (i=0; i<n; i++) {
162
-
163
- fprintf(stderr, "[%d].name : ", i);
164
-
165
- scanf(STRFMT, a[i].name);
166
-
167
- fprintf(stderr, "[%d].age : ", i);
168
-
169
- scanf("%d", &a[i].age);
170
-
171
- fprintf(stderr, "[%d].height : ", i);
172
-
173
- scanf("%lf", &a[i].height);
174
-
175
- }
176
-
177
- return n;
178
-
179
- }
180
-
181
-
182
-
183
-
184
-
185
- void str_array_print(int n, record_t a[])
186
-
187
- {
188
-
189
- int i;
190
-
191
- for (i=0; i<n; i++) {
192
-
193
- printf("%-10s", a[i].name);
194
-
195
- printf("%3d", a[i].age);
196
-
197
- printf("%7.2f", a[i].height);
198
-
199
- printf("\n");
200
-
201
- }
202
-
203
- }
204
-
205
-
206
-
207
-
208
-
209
- int main(void)
210
-
211
- {
212
-
213
- int n;
214
-
215
- record_t a[MAX_N];
216
-
217
-
218
-
219
- n = str_array_scan(a);
220
-
221
- str_sort(n, a);
222
-
223
- str_array_print(n, a);
224
-
225
-
226
-
227
- return 0;
228
-
229
- }
230
-
231
-
232
-
233
-
234
-
235
- ```

3

hファイルとメインの追加

2019/11/21 03:06

投稿

hikaru_love_n
hikaru_love_n

スコア16

test CHANGED
File without changes
test CHANGED
@@ -101,3 +101,135 @@
101
101
 
102
102
 
103
103
  ```
104
+
105
+
106
+
107
+
108
+
109
+ str_sort.hファイル↓
110
+
111
+ ```c
112
+
113
+ #define STRLEN 63
114
+
115
+ #define STRFMT "%63s"
116
+
117
+ void string_sort(int n, char (*a)[STRLEN+1]);
118
+
119
+
120
+
121
+
122
+
123
+
124
+
125
+
126
+
127
+ ```
128
+
129
+
130
+
131
+ str_sort_main.c```c
132
+
133
+ #include <stdio.h>
134
+
135
+ #include <string.h>
136
+
137
+ #include <assert.h>
138
+
139
+ #include "str_sort.h"
140
+
141
+ #define MAX_N 64
142
+
143
+
144
+
145
+
146
+
147
+ int str_array_scan(record_t a[])
148
+
149
+ {
150
+
151
+ int i;
152
+
153
+ int n;
154
+
155
+ fprintf(stderr, "n = ");
156
+
157
+ scanf("%d",&n);
158
+
159
+ assert(n<=MAX_N);
160
+
161
+ for (i=0; i<n; i++) {
162
+
163
+ fprintf(stderr, "[%d].name : ", i);
164
+
165
+ scanf(STRFMT, a[i].name);
166
+
167
+ fprintf(stderr, "[%d].age : ", i);
168
+
169
+ scanf("%d", &a[i].age);
170
+
171
+ fprintf(stderr, "[%d].height : ", i);
172
+
173
+ scanf("%lf", &a[i].height);
174
+
175
+ }
176
+
177
+ return n;
178
+
179
+ }
180
+
181
+
182
+
183
+
184
+
185
+ void str_array_print(int n, record_t a[])
186
+
187
+ {
188
+
189
+ int i;
190
+
191
+ for (i=0; i<n; i++) {
192
+
193
+ printf("%-10s", a[i].name);
194
+
195
+ printf("%3d", a[i].age);
196
+
197
+ printf("%7.2f", a[i].height);
198
+
199
+ printf("\n");
200
+
201
+ }
202
+
203
+ }
204
+
205
+
206
+
207
+
208
+
209
+ int main(void)
210
+
211
+ {
212
+
213
+ int n;
214
+
215
+ record_t a[MAX_N];
216
+
217
+
218
+
219
+ n = str_array_scan(a);
220
+
221
+ str_sort(n, a);
222
+
223
+ str_array_print(n, a);
224
+
225
+
226
+
227
+ return 0;
228
+
229
+ }
230
+
231
+
232
+
233
+
234
+
235
+ ```

2

コードの追加

2019/11/21 03:05

投稿

hikaru_love_n
hikaru_love_n

スコア16

test CHANGED
File without changes
test CHANGED
@@ -43,6 +43,8 @@
43
43
 
44
44
 
45
45
 
46
+
47
+ ```c
46
48
 
47
49
  #include<stdio.h>
48
50
 
@@ -96,8 +98,6 @@
96
98
 
97
99
  }
98
100
 
99
- ```c
100
101
 
101
- コード
102
102
 
103
103
  ```

1

コードの追加

2019/11/21 00:05

投稿

hikaru_love_n
hikaru_love_n

スコア16

test CHANGED
File without changes
test CHANGED
@@ -39,3 +39,65 @@
39
39
 
40
40
 
41
41
  と表示するようにしたい。
42
+
43
+
44
+
45
+
46
+
47
+ #include<stdio.h>
48
+
49
+ #include<string.h>
50
+
51
+ #include "str_sort.h"
52
+
53
+
54
+
55
+ void srt_sort(int n, record_t *a){
56
+
57
+
58
+
59
+ int i, j, k;
60
+
61
+ record_t min;
62
+
63
+
64
+
65
+ for(k = 0; k <= n - 2; k++){
66
+
67
+
68
+
69
+ for(i = k, j = k, min = a[k]; i < n; i++){
70
+
71
+
72
+
73
+ if(min < a[i]){
74
+
75
+
76
+
77
+ min = a[i];
78
+
79
+
80
+
81
+ j = i;
82
+
83
+ }
84
+
85
+ }
86
+
87
+
88
+
89
+ min = a[k];
90
+
91
+ a[k] = a[j];
92
+
93
+ a[j] = min;
94
+
95
+ }
96
+
97
+ }
98
+
99
+ ```c
100
+
101
+ コード
102
+
103
+ ```