Greater precision in distance problem between two points

1

I'm trying to solve a minimal tree problem, where I try to find the minimum path to connect all of us. The nodes represent objects with position defined by x, y (integers) in space, so I find the distance between one and the other by the following excerpt:

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

As I mentioned above, x and y are integers and the end result must be double with the sum of the path that travels the shortest distance to join all nodes.

What is happening is that my results are always giving similar values, however, not exact to what the system requires and my answer is not accepted.

Ex:

  

Program Exit: 98.00 Expected Exit: 98.02

How can I improve accuracy in final numbers?

    
asked by anonymous 17.08.2017 / 06:08

1 answer

0

I do not see the reason for the accuracy being incorrect, the only thing wrong seems to me to be a sqrt

I tested the code below and it worked perfectly.

#include <stdio.h>
#include <math.h>

main() {
    double dist;
    int x1 = 10, x2 = 20, y1 = 30, y2= 50;

    dist = sqrt(pow(x2 - x1, 2) + pow(y2 - y1, 2));
            printf("%.2lf", dist);
    return 0;
}

The output is

  

22.36

You can view the online test here.

    
17.08.2017 / 07:24