Construct the flowchart and code the C program that prompts the user to input the Cartesian coordinates of two points(x1, x1) and (y2-y2) and display the distance between these two points using the formula:
Distance =√(X1-X2)2 + (Y1-Y2)2
#include<stdio.h>
#include<conio.h>
#include<math.h>
int main(void)
{
int x1, x2, y1, y2, point1, point2;
float distance;
clrscr();
printf("\n\tEnter the coordinate for x1:");
scanf("%d",&x1);
printf("\n\t\t\t\tfor y1:");
scanf("%d",&y1);
printf("\n\tEnter the coordinate for x2:");
scanf("%d",&x2);
printf("\n\t\t\t\tfor y2:");
scanf("%d",&y2);
point1 =pow(x1-x2,2);
point2 =pow(y1-y2,2);
distance =sqrt(point1+point2);
printf("\n\n\n\tThe distance between the two points is %.2f",distance);
getch();
}
No comments:
Post a Comment