Calculating the simple continued fraction of a quadratic irrational

This program finds the continued fraction expansion of a quadratic irrational (u + t√d)/v, where d,t,u,v are integers, d >1 and nonsquare, t and v nonzero.
We use the continued fraction algorithm as described in K. Rosen, Elementary Number theory and its applications, 379-381 and Knuth's The art of computer programming, Vol. 2, p. 359.
The first reduced complete quotient is located and this leads to the period.

(Also see MP313 lecture notes.)
E=1 prints the partial quotients, convergents and complete quotients, whereas E=0 prints only the partial quotients.
The period is printed in bold font.

Enter d (1 < d < 1010 and not a square):
Enter t (nonzero):
Enter u:
Enter v: (nonzero)
Enter E (0 or 1):

Last modified 27th June 2006
Return to main page