home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / unix / volume8 / graph+ / part03 / max.c < prev    next >
Encoding:
C/C++ Source or Header  |  1987-03-01  |  823 b   |  41 lines

  1. /*
  2.  * Copyright (C) 1986   Alan Kent
  3.  *
  4.  * Permission is granted to freely distribute part or
  5.  * all of this code as long as it is not for profit
  6.  * and this message is retained in the code.
  7.  *
  8.  * No resposibility is taken for any damage or incorect
  9.  * results this program generates.
  10.  * 
  11.  */
  12.  
  13.  
  14. #include <stdio.h>
  15. #include "graph.h"
  16.  
  17.  
  18. double
  19. max_fun ( table , from , to )
  20. table_st *table;
  21. int from , to;
  22. {
  23.     int i;
  24.     double val;
  25.  
  26.     if ( table == NULL )
  27.     abort ( "MAX requires at least a single column table" );
  28.     if ( table->size < 1 ) {
  29.     warn ( "MAX requires at least one value in table " );
  30.     return ( 0.0 );
  31.     }
  32.     if ( to >= table->size )
  33.     to = table->size - 1;
  34.     val = table->data[from];
  35.     for ( i = from + 1; i <= to; i++ )
  36.     if ( table->data[i] > val )
  37.         val = table->data[i];
  38.     return ( val );
  39. }
  40.  
  41.