Step-by-step explanation:
None of the following for loops correctly computes the given sum:
for (int i = 1; i < n; i++) {
sum += 1/(i*i);
}
for (int i = 1; i <= n; i++) {
sum += 1/(i*i);
}
for (int i = 1; i <= n; i++) {
sum += 1.0/(i*i);
}
The correct for loop to compute the given sum is:
for (int i = 1; i <= n; i++) {
sum += 1.0/(i*i);
}
This loop correctly iterates from i=1 to i=n and uses the double data type to ensure that the division operation results in a decimal approximation.