Using rational numbers to approximate any real number : continued fractions are the best way.
For sqrt(2) as any algebraic number of degree 2, it's quite easy :
sqrt(2) = [ 1 ; 2 ; 2 ; 2 ; ... ]
which means that sqrt(2) can be approximate with :
1/1
3/2
7/5
17/12
41/29
99/70
239/169
...
275807/195025
You are asked to use a specific algorithm, involving a specific sequence ?
Variables :
P : integer
Q : integer
Initialisation :
P = Q = 1
Treatment :
While | P/Q - sqrt(2) | > 10^(-10), repeat :
P² + 2Q² -> P
2PQ -> Q
End
Output :
display P
display Q
This post was edited by feanur on Jan 18 2015 02:36pm