First, you seem like an intelligent scientist/mathematician who is trying to do some programming. I'm a physicist, and in my experience such people make some of the worst programmers; if at all possible, get some help from an experienced coder.
Second, look at this code (which is repeated, see First):
/* Move the point by q */
for(j=1;j<=3;j++){
x[g][j]=((x[g][j])+q);
}
You are modifying all three coordinates by the same amount, which means you always move a point along the (1,1,1) ray. The results improve if you modify one coordinate at a time.
Third, in the final loop (which is the one that takes most of the time) your logic is a little screwy-- you modify x, but then calculate energy using y. The results are still pretty good, because you also have x and y transposed at the end of the loop, but correcting this improves the accuracy of the results.
Fourth, and this is a big one, when you perturb a point and then recalculate energy, you recalculate the contributions of all points; only one point has changed, which means that most of the point pairs have not changed and need not be recalculated. Instead, after you choose a point, you can calculate the contribution of that point with something like this:
double oldEnergy = 0.0;
for(i=1;i<=n;i++)
{
if(i!=g)
{
Distance=myDistance(x[i], x[g]);
oldEnergy += 1.0/Distance;
}
}
Then calculate it again after the perturbation, and compare. This takes the calculation from O(n2) to O(n), which makes it a lot faster.
When I make these modifications (and make p converge 10 times faster, because I'm not very patient) my energy comes out at 49.1652530576.