← RoseCode

ROSECODE 008

Fractions to Decimals

elasolova · Programming ·

Write a program that will accept a fraction of the form ND, where N is the numerator and D is the denominator, that prints out the decimal representation. If the decimal representation has a repeating sequence of digits, it should be indicated by enclosing it in brackets. For example, 13=.33333333...is denoted as .(3), and 41333=.123123123... is denoted as .(123).

Typical conversions are:

13=.(3)
225=4.4
17=.(142857)
38=.375
4556=.803(571428)

Sample Run

ENTER N,D:1,7

17=.(142857)


What is the answer for the fraction 1159?

Source:1993 USACO Qualifying Round