I was given the following question in an interview, and I came up with the code below to compute the sum the code works and is correct, but I was told that this was a logic question and they weren't looking for the source code, can anyone shed a light on this? did they want me to write the pseudo code perhaps?
Compute the following sum:
1/2 + 1/4 + 1/8 + ... + 1/1048576
private static double computeSum()
{
double x = 0.0;
for(double i=2; i<=1048576; i*=2)
{
x += (1 / i);
}
return x;
}
No comments:
Post a Comment