Write a program that will accept a fraction of the form N/D, where N is the numerator and D is the denominator and print the decimal representation. If the decimal representation has a repeating sequence of digits, indicate the sequence by enclosing it in brackets. For example, 1/3 = .33333333...is denoted as 0.(3), and 41/333 = 0.123123123...is denoted as 0.(123). Use xxx.0 to denote an integer. Typical conversions are:
1/3 = 0.(3) 22/5 = 4.4 1/7 = 0.(142857) 2/2 = 1.0 3/8 = 0.375 45/56 = 0.803(571428)
PROGRAM NAME: fracdec
INPUT FORMAT
A single line with two space separated integers, N and D, 1 <= N,D <= 100000.
SAMPLE INPUT (file fracdec.in)
45 56
OUTPUT FORMAT
The decimal expansion, as detailed above. If the expansion exceeds 76 characters in length, print it on multiple lines with 76 characters per line.
SAMPLE OUTPUT (file fracdec.out)
0.803(571428)
解题思路:
怎样将一个分数的循环节找出来?只要反复将分子乘上10,除以分母得到该位置的数,再整除以分母,反复下去,直到出现一个已经出现过的余数,就可以找到循环节
核心代码:

本文介绍了一个程序设计问题——如何将分数转换为小数形式,并特别关注于识别并表示循环节。通过详细阐述解题思路及核心代码实现,帮助读者理解如何高效地找出并表示循环小数。
723

被折叠的 条评论
为什么被折叠?



