Monday, April 16, 2012

Can anyone help me with this logic test?

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?

  1. 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