/* File: inc2.c * * This file contains the implementations of the * functions used by inc1.c * */ /* Prototypes for the functions we use. */ int sum (int x, int y) ; int max (int x, int y) ; int min (int x, int y) ; double avg (int x, int y) ; int dist (int x, int y) ; /* Function: sum Returns the sum of x and y. */ int sum (int x, int y) { return (x + y) ; } /* Function: max Returns the larger of x and y. */ int max (int x, int y) { if (x > y) { return (x) ; } else { return (y) ; } } /* Function: min Returns the smaller of x and y. */ int min (int x, int y) { if (x < y) { return (x) ; } else { return (y) ; } } /* Function: avg Returns the average of x and y. Note: avg returns a *** double *** value. */ double avg (int x, int y) { double average ; average = (x + y) / 2.0 ; return (average) ; } /* Function: dist Returns the absolute value of x - y. */ int dist (int x, int y) { int distance ; distance = x - y ; if (distance < 0) { return (- distance) ; } else { return (distance) ; } }