Total Runs

What is meant by the number of series here are for example only the requested rate is 3 rows. Then calculated to be:
1 - 1 / 3 + 1 / 5 - 1 / 7
Note that the calculation process is the + and - changes every time the calculation process. Well, now we discuss the code:

# include <iostream>
using namespace std;

void main () {
int mp = -1;
double one = 1, re = 3;
int entry;
court <<"enter value:";
cin>> entry;

for (int ulang2 = 1; ulang2 <= entry; + + ulang2) {
a = a + ((1 / re) * mp);
mp *= -1;
re + = 2;
}

court <<one <<"\ n";
}

Logic:
Doing the calculation of the first tribe to tribe to - n (number of tribes that requested by the user). Perhaps the most "disturbing" your thinking is how to make the + and minus change - change every time, right? Though it could have been


solved simply by multiplying -1 to -1 so the results can be positive, right? If it were so, "affairs" following the wrong .

Explanation of code:
The above code is also quite clear if one looks good. At first we make some "fruit" variable:
What will be the input to / from the user, namely entry
Who will "accommodate" the result of calculation, namely one
What will be the divisor and continue to be increased in value, which is re-
Who will "change" signs and the type of calculation (of the sum to be reduced and vice versa), namely mp

Then we do the loop by adding a single variable of value 1 (at first) with the results of 1 divided by the repeated variable where its initial value is 3, and then add 2 for every loop that is then multiplied by the MP variable value -1 in the beginning so that yield calculation: 1 - (1 / 3). Variable mp then multiplied by -1 to yield positive values ​​so that the next calculation to be as follows:
1 - (1 / 3) + (1 / 5)
And so on until the calculation reaches the tribe to - n, and the calculation was done once again and stopped. The result is then indicated by a single variable. Obviously, right?

Leave reply

Back to Top