Apr 3, 2015 at 4:34pm UTC
Not to sound ignorant, but wouldn't just doing
1 2 3 4 5 6 7 8
int main()
{
float x = 1;
cout << " The summation = " << x - 0.5 + 0.25 - 0.1666666666666667 - 0.0555555555555556 + 0.05 << endl;
return 0;
}
achieve the same goal?
Last edited on Apr 3, 2015 at 4:34pm UTC
Apr 3, 2015 at 4:38pm UTC
Lines 13 and 17. They discard what could have been accumulated.
Apr 3, 2015 at 4:52pm UTC
i have to use the for lope to solve it .
keskiverto : so how i would write the code ?
Apr 3, 2015 at 7:44pm UTC
At start the sum is 1.0.
On each iteration of the loop
1. Compute value of term
2. Add or deduct the term from the sum. (Could be sum += (cond) ? term : -term ;
)