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;
}

Recommended Answers

All 5 Replies

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.