c distance between 2 points

C Program to Calculate Distance Between Two Points

To calculate the distance between two points (x1, y1) and (x2, y2) in a 2D plane, you can use the distance formula:

Distance Formula: The distance between two points (x1, y1) and (x2, y2) is given by the formula:

distance = sqrt((x2 - x1)^2 + (y2 - y1)^2)

Here's a C program to calculate the distance between two points:

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

int main() {
    float x1, y1, x2, y2, distance;

    printf("Enter the coordinates of point 1 (x1 y1): ");
    scanf("%f %f", &x1, &y1);

    printf("Enter the coordinates of point 2 (x2 y2): ");
    scanf("%f %f", &x2, &y2);

    distance = sqrt(pow((x2 - x1), 2) + pow((y2 - y1), 2));

    printf("Distance between the two points: %f\n", distance);

    return 0;
}

This program prompts the user to enter the coordinates of two points and then calculates the distance using the distance formula.

[[SOURCE 10]]