There is a simple algorithm for obtaining the continued fraction of any positive number, based on the repeated extraction of the integer part.

Observation — Algorithm for computing the continued fraction of a number

Given α>0\alpha>0, write α=a0+β0\alpha = a_0 + \beta_0 with a0=αa_0=\lfloor\alpha\rfloor the integer part and β0[0,1)\beta_0\in[0,1). If β00\beta_0\ne 0, consider 1/β01/\beta_0 and repeat: 1/β0=a1+β11/\beta_0 = a_1 + \beta_1, and so on. For αQ\alpha\in\mathbb{Q} the process terminates; for αQ\alpha\notin\mathbb{Q} it goes on forever. The expansion is periodic if and only if α\alpha is a quadratic irrational (a root of a second-degree equation with rational coefficients), a result proved by Lagrange (cf. Stillwell, ch. 5).

Topics: Second-degree equations
Concepts: Algorithm · Continued fraction · Quadratic irrational
Skills: Using formulas
People: Joseph-Louis Lagrange