回答編集履歴

1

変更箇所を色つけしました。

2021/01/29 01:33

投稿

tatsu99
tatsu99

スコア5458

test CHANGED
@@ -206,80 +206,148 @@
206
206
 
207
207
  ```diff
208
208
 
209
- 2a3
210
-
211
- > #include <string.h>
212
-
213
- 8c9,10
214
-
215
- < int i,j,t;
216
-
217
- ---
218
-
219
- > int i,j;
220
-
221
- > double t;
222
-
223
- 24c26,27
224
-
225
- < int i,j,t;
226
-
227
- ---
228
-
229
- > int i,j;
230
-
231
- > double t;
232
-
233
- 43c46
234
-
235
- < char str ={'+'};
236
-
237
- ---
238
-
239
- > char str[] = "+";
240
-
241
- 56c59
242
-
243
- < n = (double)atoi(tmp);
244
-
245
- ---
246
-
247
- > n = (double)atof(tmp);
248
-
249
- 67c70
250
-
251
- < bubble_sort1(a,i+1);
252
-
253
- ---
254
-
255
- > bubble_sort1(a,i);
256
-
257
- 69c72
258
-
259
- < bubble_sort2(a,i+1);
260
-
261
- ---
262
-
263
- > bubble_sort2(a,i);
264
-
265
- 71c74
266
-
267
- < printf("i\n");
268
-
269
- ---
270
-
271
- > printf("i=%d\n",i);
272
-
273
- 84c87
274
-
275
- < while(a[j] != '\0'){
276
-
277
- ---
278
-
279
- > for (j =0;j <i;j++){
280
-
281
- 86d88
282
-
283
- < j++;
209
+ --- goo.org.c 2021-01-29 10:27:02.142726800 +0900
210
+
211
+ +++ goo.c 2021-01-29 10:28:44.316570900 +0900
212
+
213
+ @@ -1,11 +1,13 @@
214
+
215
+ #include <stdio.h>
216
+
217
+ #include <stdlib.h>
218
+
219
+ +#include <string.h>
220
+
221
+
222
+
223
+
224
+
225
+
226
+
227
+ /*昇順のバブルソート*/
228
+
229
+ void bubble_sort1(double a[], int n){
230
+
231
+ - int i,j,t;
232
+
233
+ + int i,j;
234
+
235
+ + double t;
236
+
237
+ for(i = 0 ; i < n-1 ; i++){
238
+
239
+ for(j = n-1 ; j > i ; j--){
240
+
241
+ if(a[j-1] > a[j]){
242
+
243
+ @@ -21,7 +23,8 @@
244
+
245
+
246
+
247
+ /*降順のバブルソート*/
248
+
249
+ void bubble_sort2(double a[], int n){
250
+
251
+ - int i,j,t;
252
+
253
+ + int i,j;
254
+
255
+ + double t;
256
+
257
+ for(i = 0 ; i < n-1 ; i++){
258
+
259
+ for(j = n-1 ; j > i ; j--){
260
+
261
+ if(a[j] > a[j-1]){
262
+
263
+ @@ -40,7 +43,7 @@
264
+
265
+ char tmp[256];
266
+
267
+ double a[10];
268
+
269
+ double n;
270
+
271
+ - char str ={'+'};
272
+
273
+ + char str[] = "+";
274
+
275
+
276
+
277
+ /*ファイル入力*/
278
+
279
+ FILE *fp;
280
+
281
+ @@ -53,7 +56,7 @@
282
+
283
+ }
284
+
285
+
286
+
287
+ while(fgets(tmp, sizeof(tmp), fp) != NULL){
288
+
289
+ - n = (double)atoi(tmp);
290
+
291
+ + n = (double)atof(tmp);
292
+
293
+ a[i] = n;
294
+
295
+ i++;
296
+
297
+ }
298
+
299
+ @@ -64,11 +67,11 @@
300
+
301
+
302
+
303
+ /*昇順・降順を判断する*/
304
+
305
+ if(strcmp(argv[1],str)==0){
306
+
307
+ - bubble_sort1(a,i+1);
308
+
309
+ + bubble_sort1(a,i);
310
+
311
+ }else{
312
+
313
+ - bubble_sort2(a,i+1);
314
+
315
+ + bubble_sort2(a,i);
316
+
317
+ }
318
+
319
+ - printf("i\n");
320
+
321
+ + printf("i=%d\n",i);
322
+
323
+
324
+
325
+
326
+
327
+ /*ファイル出力*/
328
+
329
+ @@ -81,9 +84,8 @@
330
+
331
+ exit(1);
332
+
333
+ }
334
+
335
+
336
+
337
+ - while(a[j] != '\0'){
338
+
339
+ + for (j =0;j <i;j++){
340
+
341
+ fprintf(outputfile, "%f\n",a[j]);
342
+
343
+ - j++;
344
+
345
+ }
346
+
347
+
348
+
349
+ fclose(outputfile);
350
+
351
+
284
352
 
285
353
  ```