# Sum of Series?

#### Stained_Silva

##### New member
Hi Guys,

Stuck on a loop question..

Write a program to calculate and display the sum of the series:

1 - 1/2 + 1/3 - 1/4...

until a term is reached that is less than 0.0001

It might be that I have been up for hours and my brain is now dead, but I have no idea what Im supposed to do here..

You have initial value 1 and a loop for second operand that starts from 2 and counts up by 1 each iteration.

Each expression is either subtracted or added every second time, so you can use either a Boolean toggle or a "% 2" modulo expression to determine this.

By 'term' they logically mean each expression, so when you reach a value for second operand that equates to less than 0.0001 you stop looping. You could calculate what second operand that would amount to 0.0001 and use a For loop (1 / 0.0001 = 10000).

Keep a 'sum' variable that you add/subtract each loop calculated value to, to display end result.

Replies
2
Views
860
Replies
16
Views
2K
Replies
0
Views
1K
Replies
20
Views
3K
Replies
7
Views
3K