Problem

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

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);

Step-by-Step Solution

Request Professional Solution

Request Solution!

We need at least 10 more requests to produce the solution.

0 / 10 have requested this problem solution

The more requests, the faster the answer.

Request! (Login Required)


All students who have requested the solution will be notified once they are available.
Add your Solution
Textbook Solutions and Answers Search