Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I need a function. Write a C program that compute distance between two given poi

ID: 3549901 • Letter: I

Question

I need a function.  Write a C program that compute distance between two given points. please in C language

S=?((X1-X2)^2+(Y1-Y2)^2)


The sample output is


  Enter the x coordinate of the first point: -1

Invalid coordinate enter the coordinate again: 3

Enter the y coordinate of the first point: -4

Invalid coordinate enter the coordinate again: 7

Enter the x coordinate of the second point: -111

Invalid coordinate enter the coordinate again: 7

Enter the y coordinate of the second point: 4

Enter the x coordinate of the third point: -9

Invalid coordinate enter the coordinate again: 12

Enter the y coordinate of the third point: 2

Distance between point 1 and point 2 is 16.124516

Distance between point 1 and point 3 is 70.936592

Distance between point 2 and point 3 is 55.027267

Sum of distances is 142.088379

Longest distance is 70.936592 between point 1 and point 3

Shortest distance is 16.124516 between point 1 and point 2


Thanks!!!!!

Explanation / Answer

#include <stdio.h>

#include <stdlib.h>


int main()

{

int x1, x2,x3, y1, y2, y3 ;

float r1, r2, r3, l, s;

printf( "Enter the x coordinate of the first point:" );

scanf( "%d" ,&x1);

if(x1<0)

{

printf("Invalid coordinate enter the coordinate again:");

scanf( "%d" ,&x1);

}

printf( "Enter the y coordinate of the first point:" );


scanf( "%d" ,&y1);

if(y1<0)

{

printf("Invalid coordinate enter the coordinate again:");

scanf( "%d" ,&y1);

}


printf( "Enter the x coordinate of the second point:" );

scanf( "%d" ,&x2);

if(x2<0)

{

printf("Invalid coordinate enter the coordinate again:");

scanf( "%d" ,&x2);

}

printf( "Enter the y coordinate of the second point:" );


scanf( "%d" ,&y2);

if(y2<0)

{

printf("Invalid coordinate enter the coordinate again:");

scanf( "%d" ,&y2);

}


printf( "Enter the x coordinate of the third point:" );

scanf( "%d" ,&x3);

if(x3<0)

{

printf("Invalid coordinate enter the coordinate again:");

scanf( "%d" ,&x3);

}

printf( "Enter the y coordinate of the third point:" );


scanf( "%d" ,&y3);

if(y3<0)

{

printf("Invalid coordinate enter the coordinate again:");

scanf( "%d" ,&y3);

}



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

r2 = sqrt(pow((y3-y1),2) + pow((x3-x1),2));

r3 = sqrt(pow((y2-y3),2) + pow((x2-x3),2));

printf( " Distance between point 1 and point 2 is %f" ,r1);

printf( " Distance between point 1 and point 3 is %f" ,r2);

printf( " Distance between point 2 and point 3 is %f" ,r3);

printf( " Sum of distances is %f", r1+r2+r3);

if((r1>r2)&&(r1>r3)&&(r2>r3))

{

printf( " Longest distance is % f bewteen point 1 and point 2", r1);

printf( " Shortest distance is % f bewteen point 2 and point 3", r3);

}

else if((r1>r2)&&(r1>r3)&&(r2<r3))

{

printf( " Longest distance is % f bewteen point 1 and point 2", r1);

printf( " Shortest distance is % f bewteen point 1 and point 3", r2);

}

else if((r2>r1)&&(r2>r3)&&(r1>r3))

{

printf( " Longest distance is % f bewteen point 1 and point 3", r2);

printf( " Shortest distance is % f bewteen point 2 and point 3", r3);

}

else if((r2>r1)&&(r2>r3)&&(r1<r3))

{

printf( " Longest distance is % f bewteen point 1 and point 3", r2);

printf( " Shortest distance is % f bewteen point 1 and point 2", r1);

}

else if((r3>r1)&&(r3>r2)&&(r1>r2))

{

printf( " Longest distance is % f bewteen point 2 and point 3", r3);

printf( " Shortest distance is % f bewteen point 1 and point 3", r2);

}

else if((r3>r1)&&(r3>r2)&&(r1<r2))

{

printf( " Longest distance is % f bewteen point 2 and point 3", r3);

printf( " Shortest distance is % f bewteen point 1 and point 2", r1);

}



return 0;

}


Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote