home *** CD-ROM | disk | FTP | other *** search
/ C Programming Starter Kit 2.0 / SamsPublishing-CProgrammingStarterKit-v2.0-Win31.iso / tyc / list9_4.c < prev    next >
C/C++ Source or Header  |  1993-10-16  |  791b  |  41 lines

  1.  /* Passing an array to a function. */
  2.  
  3.  #include <stdio.h>
  4.  
  5.  #define MAX 10
  6.  
  7.  int array[MAX], count;
  8.  
  9.  int largest(int x[], int y);
  10.  
  11.  main()
  12.  {
  13.      /* Input MAX values from the keyboard. */
  14.  
  15.      for (count = 0; count < MAX; count++)
  16.      {
  17.          printf("Enter an integer value: ");
  18.          scanf("%d", &array[count]);
  19.      }
  20.  
  21.      /* Call the function and display the return value. */
  22.  
  23.      printf("\n\nLargest value = %d", largest(array, MAX));
  24.  }
  25.  
  26.  /* Function largest() returns the largest value */
  27.  /* in an integer array */
  28.  
  29.  int largest(int x[], int y)
  30.  {
  31.      int count, biggest = -12000;
  32.  
  33.      for ( count = 0; count < y; count++)
  34.      {
  35.          if (x[count] > biggest)
  36.              biggest = x[count];
  37.      }
  38.  
  39.      return biggest;
  40.  }
  41.