Jump to content

Continued fraction: Difference between revisions

no edit summary
m (MInor fixes)
No edit summary
Line 2,275:
call Get_Coeffs 0
return (A + Temp)</lang>
 
=={{header|Ring}}==
<lang ring>
# Project : Continued fraction
# Date : 2018/03/17
# Author : Gal Zsolt [~ CalmoSoft ~]
# Email : <calmosoft@gmail.com>
 
see "SQR(2) = " + contfrac(1, 1, "2", "1") + nl
see " e = " + contfrac(2, 1, "n", "n") + nl
see " PI = " + contfrac(3, 1, "6", "(2*n+1)^2") + nl
 
func contfrac(a0, b1, a, b)
expr = ""
n = 0
while len(expr) < (700 - n)
n = n + 1
eval("temp1=" + a)
eval("temp2=" + b)
expr = expr + string(temp1) + char(43) + string(temp2) + "/("
end
str = copy(")",n)
eval("temp3=" + expr + "1" + str)
return a0 + b1 / temp3
</lang>
Output:
<pre>
SQR(2) = 1.414213562373095
e = 2.718281828459046
PI = 3.141592653588017
</pre>
 
=={{header|Ruby}}==
2,468

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.