/*-----------------------------------------------------------------------------
Filename   : distance.c
Name       : Tristan Miller
SID#       : 123456789
Description: function for computing Euclidean distance
-----------------------------------------------------------------------------*/

#include <math.h>

/*-----------------------------------------------------------------------------
Name   : distance()
Returns: Euclidean distance between two points x and y
Args   : x[], y[] -- points to test
         n -- number of dimensions
-----------------------------------------------------------------------------*/
double distance(const double x[], const double y[], int n) {
  double result = 0.0;
  while (n--)
    result += (x[n] - y[n]) * (x[n] - y[n]);
  return sqrt(result);
}




/*=============================================================================
Here's a short program which tests our distance() function.
(This didn't have to be submitted with the file but is here to
illustrate the type of input that needs to be checked.)
=============================================================================*/
#include <stdio.h>
#include <stdlib.h>

#define N 6

double distance(const double x[], const double y[], int n);

int main(void) {
  double x[N] = {1, 2, 3, 4, 5, 6},
         y[N] = {9, 8, 7, 6, 5, 4};
  int n = N + 1;

  while (--n)
     printf("|x - y| for x, y in R^%d = %f\n", n, distance(x, y, n));

  return EXIT_SUCCESS;
}

