質問編集履歴
1
プログラミングの添付
test
CHANGED
File without changes
|
test
CHANGED
@@ -19,3 +19,83 @@
|
|
19
19
|
実装を書くこと.main.cpp には,クラス Stat のインスタンスを生成して処理を行う
|
20
20
|
|
21
21
|
main 関数を書くこと.
|
22
|
+
|
23
|
+
|
24
|
+
|
25
|
+
#include<stdio.h>
|
26
|
+
|
27
|
+
#include<string.h>
|
28
|
+
|
29
|
+
|
30
|
+
|
31
|
+
int sum(int*);
|
32
|
+
|
33
|
+
int ave(int*);
|
34
|
+
|
35
|
+
|
36
|
+
|
37
|
+
int main(void)
|
38
|
+
|
39
|
+
{
|
40
|
+
|
41
|
+
int num[3];
|
42
|
+
|
43
|
+
int n;
|
44
|
+
|
45
|
+
printf("3つの数値を入力(1,2,3):")
|
46
|
+
|
47
|
+
scanf("%d %d %d", &num[1], &num[2], &num[3]);
|
48
|
+
|
49
|
+
|
50
|
+
|
51
|
+
printf("合計値: %d \n",sum(num));
|
52
|
+
|
53
|
+
printf("平均値: %d \n",ave(num));
|
54
|
+
|
55
|
+
|
56
|
+
|
57
|
+
return 0;
|
58
|
+
|
59
|
+
}
|
60
|
+
|
61
|
+
|
62
|
+
|
63
|
+
int sum(int *all)
|
64
|
+
|
65
|
+
{
|
66
|
+
|
67
|
+
int total = 0;
|
68
|
+
|
69
|
+
|
70
|
+
|
71
|
+
for(int i=0; i<3;++i){
|
72
|
+
|
73
|
+
total += all[i];
|
74
|
+
|
75
|
+
}
|
76
|
+
|
77
|
+
|
78
|
+
|
79
|
+
return total;
|
80
|
+
|
81
|
+
}
|
82
|
+
|
83
|
+
int ave(int *all)
|
84
|
+
|
85
|
+
{
|
86
|
+
|
87
|
+
int total = 0;
|
88
|
+
|
89
|
+
|
90
|
+
|
91
|
+
for(int i=0;i<3;++i){
|
92
|
+
|
93
|
+
total += all[i];
|
94
|
+
|
95
|
+
}
|
96
|
+
|
97
|
+
|
98
|
+
|
99
|
+
return total/3;
|
100
|
+
|
101
|
+
}
|