Home > database >  calculate the value of the final order / programming
calculate the value of the final order / programming

Time:12-10

I don't know how to calculate this task with the help of loops.

enter image description here

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;
    }
}
  • Related