#include <stdio.h>
#define N 10
double sum(double [], int);
//函数的声明int main(){ double a[N]; double s = 0.0, aver = 0.0;
printf("Please input 10 real numers!\n");
for (int i = 0; i < N; i++) { scanf("%lf", a+i);
} s = sum(a, N);
//函数调用
aver = s/N;
//求平均值
printf("sum = %lf, average = %lf\n", s, aver);
return 0;}
//求和函数的实现部分double sum(double array[], int len){ int i; double sum = 0.0;
for (i = 0; i < len; i++) { sum += array[i]; } return sum; } |
|