/* * Example of using array as read-only input arguments, * ... compiler marks as an error for any attempt to change it, * */ #include #define MAX_ITEM 5 int main(void) { int x[MAX_ITEM], i, max_val; printf("Enter %d integers\n> ", MAX_ITEM); for (i = 0; i < MAX_ITEM; ++i) scanf("%d", &x[i]); max_val = get_max(x,MAX_ITEM); printf("The max value is %d\n", max_val); return (0); } /* * Returns the largest of the first n values in array list * Pre: First n elements of array list are defined and n > 0 */ int get_max(const int list[], int n) // OR get_max(const *list, int n) { int i, cur_large; cur_large = list[0]; for (i = 1; i < n; ++i) if (list[i] > cur_large) cur_large = list[i]; return (cur_large); }