0

Hello,

I'm trying to develop an algorithm/program that calculates the distance between two points. These values are stored inside a 1D array, which, acts as a 2D array (I think you know what I mean!) The values are:

150 50

15 20

The calculation should therefore be:

d = √(150 - 15)² + (50 - 20)²

Here is the code I've written (Ok, I know it's not the best way, just testing):

```
#include <iostream>
#include <math.h>
using namespace std;
int main(int argc, char *argv[]) {
int coord[2*2] = {150, 50,
15, 20};
double distance = 0;
double dis1 = 0;
double dis2 = 0;
for(int i=0; (i < 2); i++)
{
for(int j=0; (j < 2); j++)
{
dis1 = (coord[i*2+j]-coord[i*2+j])*(coord[i*2+j]-coord[i*2+j]);
dis2 = (coord[i*2+j]-coord[i*2+j])*(coord[i*2+j]-coord[i*2+j]);
}
cout << endl;
}
distance = sqrt(dis1+dis2);
cout << distance;
}
```

Anyone offer any solutions?

Thanks :)