C++循環(huán)小數(shù)的處理

字號(hào):

問題描述:
    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) //將循環(huán)部分用( )擴(kuò)起來。
    22/5 = 4.4
    1/7 = 0.(142857)
    2/2 = 1.0
    3/8 = 0.375
    45/56 = 0.803(571428)
    Input :
    A single line with two space separated integers,N and D,1<=N,D<=100000.
    Output :
    The decimal expansion, as detailed above. If the expansion exceeds 76 characters in length, print it on multiple lines with 76 characters per line.
    例子:
    輸入:45 56
    輸出:0.803(571428)
    程序代碼:
    #include
    #include
    #include
    #define LEN 100 //小數(shù)位數(shù)
    typedef struct _div
    {
    long int num; //分子
    long int den; //分母
    long int quot[LEN]; //商
    long int resi[LEN]; //余數(shù)
    unsigned long int cycle_point; //循環(huán)點(diǎn)
    unsigned long int length; //商的個(gè)數(shù)
    }DIV;