Sams Teach Yourself C in 21 Days

(singke) #1
Understanding Pointers 215

9


22: }
23: array[MAX] = 0;
24:
25: /* Call the function and display the return value. */
26: printf(ā€œ\n\nLargest value = %d\nā€, largest(array));
27:
28: return 0;
29: }
30: /* Function largest() returns the largest value */
31: /* in an integer array */
32:
33: int largest(int num_array[])
34: {
35: int count, biggest = -12000;
36:
37: for ( count = 0; num_array[count] != 0; count++)
38: {
39: if (num_array[count] > biggest)
40: biggest = num_array[count];
41: }
42:
43: return biggest;
44: }

Enter an integer value: 1
Enter an integer value: 2
Enter an integer value: 3
Enter an integer value: 4
Enter an integer value: 5
Enter an integer value: 10
Enter an integer value: 9
Enter an integer value: 8
Enter an integer value: 7
Enter an integer value: 6

Largest value = 10
Here is the output from running the program a second time:
Enter an integer value: 10
Enter an integer value: 20
Enter an integer value: 55
Enter an integer value: 3
Enter an integer value: 12
Enter an integer value: 0
Largest value = 55

LISTING9.5 continued

INPUT/
OUTPUT

INPUT/
OUTPUT

15 448201x-CH09 8/13/02 11:21 AM Page 215

Free download pdf