Continued fraction/Arithmetic/Construct from rational number: Difference between revisions
Content added Content deleted
No edit summary |
Alextretyak (talk | contribs) (Added 11l) |
||
Line 33: | Line 33: | ||
Observe how this rational number behaves differently to <math>\sqrt 2</math> and convince yourself that, in the same way as <math>3.7</math> may be represented as <math>3.70</math> when an extra decimal place is required, <math>[3;7]</math> may be represented as <math>[3;7,\infty]</math> when an extra term is required. |
Observe how this rational number behaves differently to <math>\sqrt 2</math> and convince yourself that, in the same way as <math>3.7</math> may be represented as <math>3.70</math> when an extra decimal place is required, <math>[3;7]</math> may be represented as <math>[3;7,\infty]</math> when an extra term is required. |
||
=={{header|11l}}== |
|||
{{trans|Python}} |
|||
<lang 11l>F r2cf(=n1, =n2) |
|||
[Int] r |
|||
L n2 != 0 |
|||
(n1, V t1_n2) = (n2, divmod(n1, n2)) |
|||
n2 = t1_n2[1] |
|||
r [+]= t1_n2[0] |
|||
R r |
|||
print(r2cf(1, 2)) |
|||
print(r2cf(3, 1)) |
|||
print(r2cf(23, 8)) |
|||
print(r2cf(13, 11)) |
|||
print(r2cf(22, 7)) |
|||
print(r2cf(14142, 10000)) |
|||
print(r2cf(141421, 100000)) |
|||
print(r2cf(1414214, 1000000)) |
|||
print(r2cf(14142136, 10000000))</lang> |
|||
{{out}} |
|||
<pre> |
|||
[0, 2] |
|||
[3] |
|||
[2, 1, 7] |
|||
[1, 5, 2] |
|||
[3, 7] |
|||
[1, 2, 2, 2, 2, 2, 1, 1, 29] |
|||
[1, 2, 2, 2, 2, 2, 2, 3, 1, 1, 3, 1, 7, 2] |
|||
[1, 2, 2, 2, 2, 2, 2, 2, 3, 6, 1, 2, 1, 12] |
|||
[1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 6, 1, 2, 4, 1, 1, 2] |
|||
</pre> |
|||
=={{header|C}}== |
=={{header|C}}== |