Write a program that calculates and displays the distance DIST (double type) between two points A and B whose coordinates (XA, YA) and (XB, YB) are entered in as integers
Difficulty level
Video recording
This exercise is mostly suitable for students
#include <stdio.h>
#include <math.h>
int main()
{
int XA, YA, XB, YB;
double DIST;
printf("Enter A coordinates: XA, YA ");
scanf("%d, %d", &XA, &YA);
printf("Enter B coordinates: XB, YB ");
scanf("%d, %d", &XB, &YB);
DIST = sqrt(pow(XA-XB,2) + pow(YA-YB,2));
printf("The distance between A(%d,%d) and B(%d,%d) is equal to %.2f\n",XA,YA,XB,YB,DIST);
return 0;
}
Back to the list of exercises
Looking for a more challenging exercise, try this one !!
Hopscotch hashing