/* Lnslope.c */
/* This program calculates the slope of a line. */
/* On Linux, it prints Inf if delta-x is zero. */

#include <stdio.h>

/* Global structure declarations */
struct point
  {
    float x;
    float y;
  };

struct line
  {
    struct point p1;
    struct point p2;
  };

/* function declaration */
float slope(struct line theLine);

/*begin main function */
int main()
{
 struct line L;
 float m;

 printf("Enter the x coordinate of P1: ");
 scanf("%f", &L.p1.x);
 printf("Enter the y coordinate of P1: ");
 scanf("%f", &L.p1.y);
 printf("Enter the x coordinate of P2: ");
 scanf("%f", &L.p2.x);
 printf("Enter the y coordinate of P2: ");
 scanf("%f", &L.p2.y);

 m = slope(L); /* pass the line to the slope function */

 printf("The slope of the line is %.2f.\n", m);

 return 0;
} /* end of main function */

/*begin slope function */
float slope(struct line theLine)
{
 return((theLine.p2.y - theLine.p1.y) / (theLine.p2.x - theLine.p1.x));
} /*end slope function */

