/*
 * l_dist.c
 * This program read two points and computes the distances between them
 * using several l_k norms.
 */

#include <stdio.h>
#include <math.h>

int main ()
{
  double    x1, y1;           /* The coordinates of the first point. */
  double    x2, y2;           /* The coordinates of the second point. */
  double    dist;
  int       k;

  /* Read the two points. */
  printf ("Please enter the first point: ");
  scanf ("%lf %lf", &x1, &y1);

  printf ("Please enter the second point: ");
  scanf ("%lf %lf", &x2, &y2);

  for (k = 1; k <= 20; k++)
  {
    /* Compute the l_k distance between these points:
     *                ________________________
     *             k /         k            k
     *   dist[k] = \/ |x2 - x1|  + |y2 - y1|
     */
    dist = pow (pow (fabs(x2 - x1), k) + pow (fabs(y2 - y1), k),
                1.0/(double)k);
    
    printf ("dist[%d]((%g,%g),(%g,%g)) = %g\n", k, x1, y1, x2, y2, dist);
  }

  return (0);
}

