-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1209-2.c
More file actions
38 lines (34 loc) · 748 Bytes
/
1209-2.c
File metadata and controls
38 lines (34 loc) · 748 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#include <stdio.h>
#define DEBUG
double calc_array_avg(int *a, int size);
int main(void)
{
int a[10] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
double avg = calc_array_avg(a, 10);
printf("배열의 평균 : %.1lf\n", avg);
return 0;
}
double calc_array_avg(int *a, int size)
{
#ifdef DEBUG
printf("start of calc_array_avg()...\n");
for (int i = 0; i< size; i++)
{
printf("%d", a[i]);
}
printf("\n");
#endif
double sum = 0;
for (int i=0; i<size; i++) {
sum += a[i];
#ifdef DEBUG
printf("%d을(를) 더하는 중...\n", a[i]);
#endif
}
double avg = sum / size;
#ifdef DEBUG
printf("평균=%.1lf\n", avg);
printf("end of clac_array_avg()... \n");
#endif
return avg;
}