@Never, thanks!
@Musa, your code is fine and easy to understand. That's how I write mine. I know am not answering your question directly, but still any speed gained here might help in general, so I hope you don't mind.
The first inner loop can accept some change, as well. For instance, instead of Power in:
ZArray[k-1]:= ZValues[k-1] * A * exp(-Pi*power(A/1000*(XValues[k-1]-XValues[n-1]), 2));
you can use IntPower for integer exponent values. Power and IntPower have the same accuracy:
ZArray[k-1]:= ZValues[k-1] * A * exp(-Pi*intpower(A/1000*(XValues[k-1]-XValues[n-1]), 2));
In case of 2, I think a simple multiplication should be faster with (or without?) optimization.
Ad1000 := A/1000;
..
deltaX := Ad1000*(XValues[k-1]-XValues[n-1]);
ZArray[k-1]:= ZValues[k-1] * A * exp(-Pi*deltaX*deltaX);
But it does not have the same accuracy.