C program for the Distance between the two points.
It uses the following formula give points are (x1,y1) and (x2, y2)
SQRT( (x2-x1) * (x2-x1) + (y2-y1) * (y2-y1) )
Source Code
#include <stdio.h>
#include <math.h>
void main()
{
float distance;
int x1, y1, x2, y2;
int dx, dy;
printf("Program for distance between the two points\n");
printf("Enter X1: ");
scanf("%d", &x1);
printf("Enter Y1: ");
scanf("%d", &y1);
printf("Enter X2: ");
scanf("%d", &x2);
printf("Enter Y2: ");
scanf("%d", &y2);
dx = x2 - x1;
dy = y2 - y1;
distance = sqrt(dx*dx + dy*dy);
printf("%.4f", distance);
}
Output
Program for distance between the two points
Enter X1: 10
Enter Y1: 10
Enter X2: 30
Enter Y2: 30
Distance between (10, 10) and (30, 30) = SQRT(800) = 28.2843
#include
উত্তরমুছুন#include
void main()
{
float distance;
int a1, b1, a2, b2;
int dx, dy;
printf("Program for distance between the two points\n");
printf("Enter a1: ");
scanf("%d", &a1);
printf("Enter b1: ");
scanf("%d", &b1);
printf("Enter a2: ");
scanf("%d", a2);
printf("Enter b2: ");
scanf("%d", &b2);
dx = a2 - a1;
dy = b2 - b1;
distance = sqrt(dx*dx + dy*dy);
printf("%.4f", distance);
}