Distance between n points

  • (2 Pages)
  • +
  • 1
  • 2

18 Replies - 15748 Views - Last Post: 28 March 2011 - 11:26 PM Rate Topic: -----

#16 Giorgio33   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 9
  • Joined: 24-March 11

Re: Distance between n points

Posted 28 March 2011 - 06:00 PM

Thanks my friend, but I have a[200][2].
a[4][2] is only for test.
Was This Post Helpful? 0
  • +
  • -

#17 JaKWaC   User is offline

  • D.I.C Head

Reputation: 76
  • View blog
  • Posts: 234
  • Joined: 15-November 10

Re: Distance between n points

Posted 28 March 2011 - 06:03 PM

What does that have to do with anything? Change arr[7][2] to arr[200][2], it all works the same. Hell I could make it dynamic and expand till the end of a file is read in, or ask the user for a number of points to randomly generate.

The loop will still work.

This post has been edited by JaKWaC: 28 March 2011 - 06:11 PM

Was This Post Helpful? 1
  • +
  • -

#18 Giorgio33   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 9
  • Joined: 24-March 11

Re: Distance between n points

Posted 28 March 2011 - 11:19 PM

Thank you JaKWaC. The program is reading the file and calculating the average distance between points.


s +=d;
m=s/((N-1)*N/2);



What can I do to get only the last value? ---> d_média = 3.353

file.in:
2 0
3 0
0 5
2 1
3 1
6 8

m = 0.06667
m = 0.3722
m = 0.4388
m = 0.4388
m = 0.9007

m = 1.167
m = 1.167
m = 1.234
m = 1.728

m = 1.959
m = 2.136
m = 2.482

m = 2.549
m = 2.932

m = 3.353

This post has been edited by Giorgio33: 28 March 2011 - 11:23 PM

Was This Post Helpful? 0
  • +
  • -

#19 JaKWaC   User is offline

  • D.I.C Head

Reputation: 76
  • View blog
  • Posts: 234
  • Joined: 15-November 10

Re: Distance between n points

Posted 28 March 2011 - 11:26 PM

You mean calculate the distance between the last two points?

You could take the number of points in your array and do the math for, a[MAX_ELEMENTS-1] and a[MAX_ELEMENTS-2] (where MAX_ELEMENTS is the size of your array, -1 gives you the last elements, -2 gives you the second to last.)

This post has been edited by JaKWaC: 28 March 2011 - 11:27 PM

Was This Post Helpful? 1
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2