简体   繁体   中英

Declare and define the function distance() to find the Euclidean distance between the two points (x[0], y[0]) and (x[1], y[1]) in c

Declare and define the function distance() to find the Euclidean distance : √((x1 - x2)² + (y1 - y2)²) between the two points (x[0], y[0]) and (x[1], y[1]) This function should just calculate and return the answer.

C PROGRAM -----

double distance(double x[], double y[]) ;

What else am I supposed to put. Do I include the eculidean distance in this function or create a new one?

double distance(double x[], double y[]);

is the function declaration.

double distance(double x[], double y[]) {
    //Write code here that returns a double
}

is the function definition.

Looks like the problem wants you to do both.

This is the simplest distance() function definition:

`double distance(double x, double y){
    return 1/sqrt(((x[0]-x[1])*(x[0]-x[1])+(y[0]-y[1])*(y[0]-y[1])));
}`

Note that if you are using it to compare distances it's fastest to use the square of the distances.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM