/* * File Name : straight-line_distance.c * Title : Straight-line Distance Calculation Program * Author : Buff Furman * Lab Section : day * Assignment : Lab_1 * Created : 18AUG2009 * Revised : 18AUG2009 * Version : 1.0 * Description : Calculates the straight-line distance between two points * Inputs : x and y ordered pairs for two points: x1, y1 and x2, y2 * Outputs : straight-line distance between the two points * Method : Get points from the user * Echo what was entered to the monitor * Calculate the distance, D=sqrt((x2-x1)^2 + (y2-y1)^2) * Display D to the monitor * Revision History: * Date Who Description of Change * ------- --------- --------------------------- * 18AUG2009 BF Created program */ /*---------Include Files--------------*/ #include /* standard IO library routines, like printf(), scanf() */ #include /* standard math library routines, like sqrt() */ /*---------Macros---------------------*/ /* none in this program */ /*---------Function Prototypes--------*/ /* none in this program */ /*---------Global Variables-----------*/ /* none in this program */ /*---------Body of Program Code-------*/ int main(void) { double X1, X2, Y1, Y2; /* variables for the xy coordinates of P1 and P2 */ double D; /* distance between P1 and P2 */ /* Get the points from the user */ printf("\nEnter the first point, P1, in the form, x1 y1> "); scanf("%lf %lf", &X1, &Y1); printf(" You entered: P1 = (%g, %g)\n", X1, Y1); printf("\nEnter the second point, P2, in the form, x2 y2> "); scanf("%lf %lf", &X2, &Y2); printf(" You entered: P2 = (%g, %g)\n", X2, Y2); /* Calculate the straight-line distance between P1 and P2 */ D = sqrt(pow((X2-X1),2) + pow((Y2-Y1),2)); /* Display the distance */ printf("\nThe straight-line distance between P1 and P2 is %.4f \n\n", D); return 0; } /*---------Function Definitions-------*/ /* none in this program */