Anonymous user
Continued fraction: Difference between revisions
m
<math> is awesome
m (Shrink the image a bit, fix a typo) |
m (<math> is awesome) |
||
Line 1:
{{draft task}}A number may be represented as a continued fraction (see http://mathworld.wolfram.com/ContinuedFraction.html) as follows:
:<math>cf = a_1 + \cfrac{b_1}{a_2 + \cfrac{b_2}{a_3 + \cfrac{b_3}{\mathrm{etc\ldots}}}}</math>
The task is to write a program which generates such a number and prints a real representation of it.
The code should be tested by calculating and printing the square root of 2, Napier's Constant, and Pi.
For the square root of 2,
For Napier's Constant,
For Pi,
=={{header|Python}}==
<lang python># The continued Fraction▼
▲# The continued Fraction
def CF(a, b, t):
if 0 < t:
Line 86 ⟶ 82:
cf = CF(Pi_a(), Pi_b(), 950)
print(pRes(cf, 10))
#3.1415926532</lang>
|