0
My question is in the letter B, I am asked to count between the first 20 terms, how do I do this limitation of 20 terms of the account? I even put the formula in is (i = 5, j = 3; i += 2, j += 2) But it remains to introduce the i e j interval that is my doubt. Thank you
The question follows: Calculate the sum of the following series : a) S = 1 + 1/3 + 1/5 + 1/7 + .........+ 1/99
b) S = 1 - 1/3 + 1/5 - 1/7 + ............ ... for the first 20 terms
int i, j;
double soma = 1, result = 1;
printf ("Somatorio dos termos: S = 1 + 1/3 + 1/5 + 1/7 + ............+ 1/99 \n");
for (i = 3; i <= 99; i += 2) {
soma = soma + (1.0/i);
}
printf ("a) Soma = %lf \n\n", soma);
for (i = 5, j = 3; ;i += 2, j += 2) {
result = result - 1.0/j + 1.0/i;
}
printf ("b) Resultado = %lf \n\n", result);
system ("PAUSE");
Thanks for the tips guys, I managed to do otherwise, probably not in the "correct" way but the result of the same. for (k = 5, j = 3, cont = 0; cont < 20 ; k += 2, j += 2, cont++) { result = result - 1.0/j + 1.0/k; } At least it’s the way I can think without bugging my mind
– Tsr N