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

  1.  /* Passing an array to a function. Alternative way. */
  2.  
  3.  #include <stdio.h>
  4.  
  5.  #define MAX 10
  6.  
  7.  int array[MAX+1], count;
  8.  
  9.  int largest(int x[]);
  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.          if ( array[count] == 0 )
  21.              count = MAX;                /* will exit for loop */
  22.      }
  23.      array[MAX] = 0;
  24.  
  25.      /* Call the function and display the return value. */
  26.  
  27.      printf("\n\nLargest value = %d", largest(array));
  28.  }
  29.  
  30.  /* Function largest() returns the largest value */
  31.  /* in an integer array */
  32.  
  33.  int largest(int x[])
  34.  {
  35.      int count, biggest = -12000;
  36.  
  37.      for ( count = 0; x[count] != 0; count++)
  38.      {
  39.          if (x[count] > biggest)
  40.              biggest = x[count];
  41.      }
  42.  
  43.      return biggest;
  44.  }
  45.