C Program to Calculate the distance between the two points - IProgramX

Q. Accept the x and y coordinates of two point and compute the distance between the two points


Program

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

int main()
{
    float distance, a, b, c, d;
    printf("\nEnter The Coordinates of Point A:\n");
    printf("\nX - Axis Coordinate: \t");
    scanf("%f", &a);
    printf("\nY - Axis Coordinate: \t");
    scanf("%f", &b);  
    printf("\nEnter The Coordinates of Point B:\n");
    printf("\nx - Axis Coordinate:\t");
    scanf("%f", &c);
    printf("\nY - Axis Coordinate: \t");
    scanf("%f", &d);
    distance = sqrt((c - a) * (c - a) + (d - b) * (d- b));
    printf("\nDistance between Points A and B: %f\n",  distance);
    return 0;
}

Output:

Enter The Coordinates of Point A:

X - Axis Coordinate:    5

Y - Axis Coordinate:    2

Enter The Coordinates of Point B:

x - Axis Coordinate:    8

Y - Axis Coordinate:    4

Distance between Points A and B: 3.605551

Post a Comment

0 Comments