#include int sum1D(int n, int arr[]); void zero(int n, int arr[]); void zero2D(int n, int m, int arr[][m]); int *make_array(int n); int main() { int a[5] = {12, 24, 45, 99, 100}; int a2d[3][3] = {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}}; int b2d[3][4]; zero2D(3, 4, b2d); printf("%d\n", sum1D(5, a)); printf("%d\n", sum1D(3, a2d[1])); // row of 2-D array is a 1-D array printf("%d\n", sum1D(4, a2d[1])); // lying about size -- wraps around to next row printf("%d\n", sum1D(3, b2d[0])); // sum is zero, of course, since we zeroed it with zero2D int *arr15 = make_array(15); printf("%d\n", sum1D(15, arr15)); } void zero2D(int n, int m, int arr[][m]) { for (int r = 0; r < n; r++) { for (int c = 0; c < m; c++) { arr[r][c] = 0; } } } void zero(int n, int *arr) // as a parameter, int arr[] is equiv to int *arr { for (int i = 0; i < n; i++) { arr[i] = 0; } } int sum1D(int n, int *arr) { int sum = 0; for (int i = 0; i < n; i++) { sum += arr[i]; } return sum; } // The *WRONG* way to write a function that returns an array. // Note the helpful compiler warning about returning a pointer to // a local variable -- a variable that is going to get bulldozed at the } // // |7 // }o===o someone please draw me a better ASCII-art bulldozer int *make_array(int n) { int result[n]; for (int i = 0; i < n; i++) { result[i] = i; } return result; }