Problem I. 115. (November 2005)
I. 115. It is wellknown that every rational number x can uniquely be represented as a finite continued fraction:
where a_{0} is an integer, and a_{1},...,a_{n} are positive integers, further a_{n}>1. The terms of the continued fraction are obtained by a simple greedy algorithm. Number a_{0} can only be the integer part of x. If x is an integer, then we are ready. Otherwise, if x is not an integer, we have , with , and now we have to find a representation only for y.
Write a program that converts ordinary fractions into their continued fraction form.
The program should read the ordinary fractions from the standard input (i.e. from the keyboard). Every line will contain a fraction of the form a/b, where a and b are integers with at most 4 digits. Your program should display the continued fraction representation of these numbers on the standard output (i.e. on the monitor), using parentheses as in the example. Your program should stop if the standard input can not be read (``end of file''), or the input is an empty line.
See the example.
The source code of your program (i115.pas, i115.c, ...) should be submitted.
(10 pont)
Deadline expired on 15 December 2005.
Statistics:
