/* #include directives */ #include <stdio.h> #include <stdbool.h> /* #define directives */ #define N 10 /* declarations of exteral variables */ /* empty exteral variables */ /* prototypes */ void avg_sum(double a[], int n, double *avg, double *sum); void print(const double *avg, const double *sum); /*************************************************** * main: calls avg_sum, print; * * * ***************************************************/ int main(void) { double array[N], avg, sum; int i; for( ; ;) { char ch; printf("\n\n\tgo to main(y/n):"); scanf("%c",&ch); while(getchar() != '\n') /* empty loop body*/; if(ch == 'y' ||ch == 'Y') { printf("\n\n\tEnter %d of double number: ",N); for(i = 0; i < N; i++) scanf("%lf",&array[i]); avg_sum(array, N, &avg, &sum); print(&avg, &sum); } else break; } return 0; } /*************************************************** * functions: avg_sum, print * * * ***************************************************/ void avg_sum(double a[], int n, double *avg, double *sum) { int i; *sum = 0; for(i = 0; i < n; i++) *sum += a[i]; *avg = *sum / n; return; } void print(const double *avg, const double *sum) { printf("\n\n\tavg = %g",*avg); printf("\n\n\tsum = %g",*sum); return; } /*************************************************** * test point * ***************************************************/
onemoo
乔巴之无所不能
相关分类