質問編集履歴
1
追記
test
CHANGED
File without changes
|
test
CHANGED
@@ -85,3 +85,95 @@
|
|
85
85
|
```
|
86
86
|
|
87
87
|
上記の関数で計算した結果を関数内で表示するのではなく、main関数に計算結果を返してmain関数内で計算結果を```pfintf```で表示させたいです。
|
88
|
+
|
89
|
+
|
90
|
+
|
91
|
+
```c
|
92
|
+
|
93
|
+
#include <stdio.h>
|
94
|
+
|
95
|
+
|
96
|
+
|
97
|
+
void input_array( int *a, int n );
|
98
|
+
|
99
|
+
void calc_age( int *a, int n, int y );
|
100
|
+
|
101
|
+
|
102
|
+
|
103
|
+
int main(void)
|
104
|
+
|
105
|
+
{
|
106
|
+
|
107
|
+
int key[5];
|
108
|
+
|
109
|
+
int y=0;
|
110
|
+
|
111
|
+
|
112
|
+
|
113
|
+
printf("現在の年齢\n");
|
114
|
+
|
115
|
+
input_array(key, 5);//渡し方についての勉強をする
|
116
|
+
|
117
|
+
printf("何年後?"); scanf("%d",&y);
|
118
|
+
|
119
|
+
printf("10 年後の年齢\n");
|
120
|
+
|
121
|
+
int total = 0;
|
122
|
+
|
123
|
+
calc_age(key,5,y);
|
124
|
+
|
125
|
+
|
126
|
+
|
127
|
+
for (int i=0;i<5; i++)
|
128
|
+
|
129
|
+
{
|
130
|
+
|
131
|
+
printf("%d人目:%d\n",i+1,total);
|
132
|
+
|
133
|
+
}
|
134
|
+
|
135
|
+
return 0;
|
136
|
+
|
137
|
+
}
|
138
|
+
|
139
|
+
|
140
|
+
|
141
|
+
void input_array( int *a, int n )
|
142
|
+
|
143
|
+
{
|
144
|
+
|
145
|
+
for (int i=0;i<n; i++)
|
146
|
+
|
147
|
+
{
|
148
|
+
|
149
|
+
printf("%d人目:",i+1); scanf("%d", a+i);
|
150
|
+
|
151
|
+
}
|
152
|
+
|
153
|
+
|
154
|
+
|
155
|
+
}
|
156
|
+
|
157
|
+
|
158
|
+
|
159
|
+
void calc_age( int *a, int n, int y )
|
160
|
+
|
161
|
+
{
|
162
|
+
|
163
|
+
|
164
|
+
|
165
|
+
for (int i=0;i<n; i++)
|
166
|
+
|
167
|
+
{
|
168
|
+
|
169
|
+
*a = *(a+i)+y;
|
170
|
+
|
171
|
+
}
|
172
|
+
|
173
|
+
|
174
|
+
|
175
|
+
}
|
176
|
+
|
177
|
+
|
178
|
+
|
179
|
+
```
|