52.0k views
5 votes
Draw a flow chart and write pseudocode for an iterative algorithm that calculates 1 - 1/2 +1/3 - ... +(or -) 1/n. 1/k is added to the sum if k is odd and subtracted from the sum if k is even. (This sum converges in 2, the natural logarithm of 2).

User Gjorgji
by
3.3k points

1 Answer

3 votes

Answer:

PSEUDOCODE

BEGIN

A = 0

n = 1

Input Number

Loop :

do while n <= Number

A = A + (-1)^(n+1) * (1/n)

n = n + 1

return to loop

print A

END

See attachment for Flowchart

Explanation:

Assume number = 3

First Loop : A = 0 + (-1)^2 * 1/1 = 1

Second Loop : A = 1 and n = 2

A = 1 + (-1)^(2+1) * 1/2 = 1 - 1/2

Third Loop : A = 1 - 1/2 and n = 3

A = 1 - 1/2 (-1)^(3+1) * 1/3 = 1 - 1/2 + 1/3

Print A will then print 5/6

Draw a flow chart and write pseudocode for an iterative algorithm that calculates-example-1
User Rgdesign
by
3.3k points