I have the coordinates of n points and I need to calculate the distance between each point until the other points.

2 0
3 0
0 5
2 1
...
...
...
I am beginner in C + + and I've worked a lot before asking for help.
Already, I thank you for the help.

``````#include <iostream>
#include <fstream>
# include <stdio.h>
# include <cmath>
#define N 4
#define M 2

using namespace std;

int main()
{
int i,j,k;
double **a;
a=new double *[N+1];
for (i=0;i<=N;i++)
a[i]=new double [N+1];

ifstream inputfile;

inputfile.open("file.in");

if(inputfile.fail())

{

cout<<"The file could not be opened!\n";

}

//row operations
double m;
for (j=0;j<=1;j++)
for (i=0;i<=N-1;i++)
for (k=i+1;k<=N-1;k++)
{

m[i][j]=sqrt(pow((a[k][1]-a[i][1]),2)-(pow((a[k][2]-a[i][2]),2)));
m += a[i][j];
cin >> i,j,a[i][j];

}

for (i=1;i<=N;i++)
{
for (j=1;j<=N;j++)
cout <<  a[i][j] << "  ";
cout << endl;
}

cout << endl;
return 0;
}``````

Edited by Giorgio33: n/a

3
Contributors
5
Replies
6
Views
7 Years
Discussion Span
Last Post by WaltP

In order to get help, you need to ask a question, not just post code and hope we can figure out if there's an error and what it might be..

What is not working??

``m[i][j]=sqrt(pow((a[k][1]-a[i][1]),2)-(pow((a[k][2]-a[i][2]),2)));``

How can I make the loop?

``````#
for (j=0;j<=1;j++)
#
for (i=0;i<=N-1;i++)
#
for (k=i+1;k<=N-1;k++)
#
{
#

#
m[i][j]=sqrt(pow((a[k][1]-a[i][1]),2)-(pow((a[k][2]-a[i][2]),2)));``````

It seems that you don't really want help because in 3 posts you've told us nothing about your problem and have ignored two requests for an explanation.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.