I don't know how to calculate this task with the help of loops.
CodePudding user response:
It would be something like this:
double S = 0;
for (int i = 1; i <= n; i) {
double T = 1.0/(double)i;
if (i%2 == 0) {
S -= T;
} else {
S = T;
}
}