Unlike the harmonic numbers, the sum 1/12 + 1/22 + ... + 1/n2 does converge to a

Question:

Unlike the harmonic numbers, the sum 1/12 + 1/22 + ... + 1/n2 does converge to a constant as n grows to infinity. (Indeed, the constant is 2/6, so this formula can be used to estimate the value of .) Which of the following for loops computes this sum? Assume that n is an int variable initialized to 1000000 and sum is a double variable initialized to 0.0.

a. for (int i = 1; i <= n; i++) sum += 1 / (i*i);

b. for (int i = 1; i <= n; i++) sum += 1.0 / i*i;

c. for (int i = 1; i <= n; i++) sum += 1.0 / (i*i);

d. for (int i = 1; i <= n; i++) sum += 1 / (1.0*i*i);

Fantastic news! We've Found the answer you've been seeking!

Step by Step Answer:

Related Book For  answer-question
Question Posted: