/********************************************
* File: stats.c
* Author: S. Bogar
* Date: 8/3/99
* Section 101
* SSN: 123-45-6789
* EMail: bogar@cs.umbc.edu
*
* This file is compiled separately from findstats.c
*
* Functions in this file:
* Sum (x, y)
* Min (x, y)
* Max (x, y)
* Avg (x, y)
* Dist (x, y)
*
*********************************************/
/***********************************
* Header files needed by the code
* found in the functions defined
* in this file
************************************/
#include "stats.h"
/********************************************
* Function: Sum
* Usage: z = Sum (x, y)
*
* Input: two integers to be added
* Output: Returns the sum of x and y.
*********************************************/
int Sum (int x, int y)
{
int sum ;
sum = (x + y) ;
return sum ;
}
/*********************************************
* Function: Max
* Usage: z = Max (x, y)
*
* Inputs: two integers to be compared
* Output: Returns the larger of x and y.
*********************************************/
int Max (int x, int y)
{
int max ;
if (x > y) {
max = x ;
} else {
max = y ;
}
return max ;
}
/*********************************************
* Function: Min
* Usage: z = Min (x, y)
*
* Inputs: two integers to be compared
* Output: Returns the smaller of x and y.
*********************************************/
int Min (int x, int y)
{
int min ;
if (x < y) {
min = x ;
} else {
min = y ;
}
return min ;
}
/*********************************************
* Function: Avg
* Usage: z = Avg (x, y)
*
* Inputs: two integers to be compared
* Output: Returns average of x and y as a
* *** double ***
*
*********************************************/
double Avg (int x, int y)
{
double average ;
average = (x + y) / 2.0 ;
return average ;
}
/*********************************************
* Function: Dist
* Usage: z = Dist (x, y)
*
* Input: two integers for which distance is
* calulated
* Output:Returns the absolute value of x - y.
*********************************************/
int Dist (int x, int y)
{
int distance ;
distance = x - y ;
if (distance < 0) {
distance = -distance ;
}
return distance ;
}