The Leibniz formula is a series that calculates 1 - 1/3 + 1/5 - 1/7 + 1/9 - 1/11 + ...... for an infinite number of terms.Write a function, Leibniz, which takes a number of terms as its arguments and returns the result of the Leibniz formula for that number of terms.Leibniz(1) returns 1Leibniz(2) returns .66666666667Leibniz(3) returns .86666666667Write a program which calls the Leibniz function with a number of terms of 100, stores the result, and prints the stored results * 4. From the result, what do you believe the Leibniz formula approximates?
What will be an ideal response?
start
num terms = 100
num result
result = Leibniz(terms)
print result * 4
stop
Leibniz(num terms)
num sign = 1
num sum = 0
num denom = 1
for num x = 1 to terms
sum += sign / denom
denom = denom + 2
sign = sign * -1
endfor
return sum
The Leibniz function would return approximately 0.78539816. This result multiplied by 4 is 3.14159264. The Leibniz function approximates pi.
You might also like to view...
In an OpenOffice Base database, the Database ________ is where you can navigate between objects in your database
Fill in the blank(s) with correct word
Changing theme fonts changes all the text in a presentation instantaneously, which can be a big time-saver.
Answer the following statement true (T) or false (F)
Item D in the accompanying figure shows the name of the _______________ image.
Fill in the blank(s) with the appropriate word(s).
The Append query can create a table and add records to it at the same time.
Answer the following statement true (T) or false (F)