I was given the following question in an interview...
Compute the following sum:
1/2 + 1/4 + 1/8 + ... + 1/1048576
I was told that this was a logic question and they weren't looking for the source code, however my answer was the following...
private static double computeSum(){
double x = 0.0;
for(double i=2; i<=1048576; i*=2){
x += (1 / i);
}
return x;
}
What is the correct logical answer to this question?