Write c program to accept the x and y coordinates of two points and compute the distance between the two points.

#include<conio.h>
#include<stdio.h>

//To calculate distance between 2 points 
void distance(float x1,float y1,float x2,float y2)
{
float ans1,ans2;
ans1=x1-x2;
        ans2=y1-y2;
        // %f is place holder for floating point values 
        printf("Distance between two points is: %f x %f y.",ans1,ans2); }

void main()
{
   float x1,y1,x2,y2;  //declaration of x1,y1,x2,y2
   
   //accept values of x1,x2,y1,y2
   printf("\nEnter value of x1: ");
   scanf("%f",&x1);

   printf("\nEnter value of y1: ");
   scanf("%f",&y1);
   
   printf("\nEnter value of x2: ");
   scanf("%f",&x2);
   
   printf("\nEnter value of y2: ");
   scanf("%f",&y2);
   
    //calling distance function 
   distance(x1,y1,x2,y2);
   getch();
}

0 Comments