/* * Example of returning an array result * */ #include #define NSIZE 5 void add_arrays(const double ar1[], const double ar2[], double arsum[], int n); int main() { double x[NSIZE] = {1.5, 2.2, 3.4, 5.1, 6.7}; double y[NSIZE] = {2.0, 4.5, 1.3, 4.0, 5.5}; double xpy[NSIZE]; int i; add_arrays(x, y, xpy, 5); // note: no address-of operator & for xpy printf("the sum of x+y = "); for (i=0; i < NSIZE; ++i) printf(" %.1f", xpy[i]); printf("\n"); return 0; } /* * Adds corresponding elements of arrays ar1 and ar2, * storing the result in arsum. */ void add_arrays(const double ar1[], const double ar2[], double arsum[], int n) { int i; for (i = 0; i < n; ++i) arsum[i] = ar1[i] + ar2[i]; }