Thanks my friend, but I have a[200][2].
a[4][2] is only for test.
18 Replies - 15748 Views - Last Post: 28 March 2011 - 11:26 PM
#17
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.
The loop will still work.
This post has been edited by JaKWaC: 28 March 2011 - 06:11 PM
#18
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.
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
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
#19
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.)
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

New Topic/Question
Reply



MultiQuote


|