-
Notifications
You must be signed in to change notification settings - Fork 0
/
148.c
57 lines (37 loc) · 792 Bytes
/
148.c
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#include <stdio.h>
void input(double a[], size_t size) {
size_t i;
for(i = 0; i < size; i++ ) {
printf("enter number:");
scanf("%lf",&a[i]);
}
}
void print(double a[], size_t size) {
size_t i;
for(i = 0; i < size; i++ ) {
printf(" [%zu]: %lf\n",i,a[i]);
}
}
double sum(double *a, size_t len) {
double sum = 0;
size_t i;
while (len--)
sum += *a++;
return sum;
}
int main(void) {
int SIZE;
char answer;
printf("How many numbers do you want to store?");
scanf("%d", &SIZE);
double a[SIZE];
input(a, SIZE);
print(a, SIZE);
printf("want to calculate the total?\n y/n\n");
scanf(" %c",&answer);
//printf("answer %c\n",answer);
if(answer =='y') {
double res = sum(a,SIZE);
printf("Sum: %lf\n",res);
}
}