質問編集履歴

3

修正

2020/01/08 05:25

投稿

sansan1
sansan1

スコア7

test CHANGED
File without changes
test CHANGED
@@ -84,7 +84,7 @@
84
84
 
85
85
 
86
86
 
87
- printf("%d", n);
87
+ **printf("%d", n);**
88
88
 
89
89
  printf("平均値は%.1f", AVE);
90
90
 
@@ -110,4 +110,4 @@
110
110
 
111
111
 
112
112
 
113
- ここにより詳細な情報を記載してください。
113
+ 実行すると5個か入力していないのに、整数の個数が20個と出てきてしまいます

2

書式の改善

2020/01/08 05:24

投稿

sansan1
sansan1

スコア7

test CHANGED
File without changes
test CHANGED
@@ -18,7 +18,9 @@
18
18
 
19
19
 
20
20
 
21
+ ```
22
+
21
- ```#include <stdio.h>
23
+ #include <stdio.h>
22
24
 
23
25
  #include <math.h>
24
26
 
@@ -26,7 +28,7 @@
26
28
 
27
29
  double average(int v[], int n)
28
30
 
29
- {
31
+ {
30
32
 
31
33
  int i;
32
34
 
@@ -39,6 +41,8 @@
39
41
  for (i = 0; i < n; i++)
40
42
 
41
43
  sum += v[i];
44
+
45
+
42
46
 
43
47
  AVE = sum / n;
44
48
 
@@ -54,11 +58,11 @@
54
58
 
55
59
  {
56
60
 
57
- int n, i;
61
+ int n = 0;
58
62
 
59
63
  int v[20];
60
64
 
61
- int sum = 0;
65
+ double AVE;
62
66
 
63
67
 
64
68
 
@@ -66,31 +70,29 @@
66
70
 
67
71
 
68
72
 
69
- for(i=0; i < 20; i++) {
73
+ do {
70
74
 
71
- scanf("%d", &v[i]);
75
+ scanf("%d", &v[n]);
76
+
77
+ n++;
78
+
79
+ } while (n < 20 && v[n] != EOF);
72
80
 
73
81
 
74
82
 
75
- if (v[i] == EOF)
83
+ AVE = average(v, n);
76
-
77
- break;
78
-
79
- }
80
-
81
- n = i;
82
84
 
83
85
 
84
86
 
85
87
  printf("%d", n);
86
88
 
87
- printf("平均値は%.1f", average(v, n));
89
+ printf("平均値は%.1f", AVE);
88
90
 
89
91
 
90
92
 
93
+ return 0;
94
+
91
95
  }
92
-
93
-
94
96
 
95
97
  ```
96
98
 

1

書式の改善

2020/01/08 05:23

投稿

sansan1
sansan1

スコア7

test CHANGED
File without changes
test CHANGED
@@ -18,7 +18,7 @@
18
18
 
19
19
 
20
20
 
21
- #include <stdio.h>
21
+ ```#include <stdio.h>
22
22
 
23
23
  #include <math.h>
24
24
 
@@ -92,6 +92,10 @@
92
92
 
93
93
 
94
94
 
95
+ ```
96
+
97
+
98
+
95
99
  ### 試したこと
96
100
 
97
101