2016-11-10 1 views
-1

꺾쇠 괄호 안에 반복되는 소수점 이하 자리수를 최소로 사용하여 십진수로 변환하려고합니다. 그것은 다음과 같이해야합니다 : 출력해야 0.(3)파스칼에서 분수를 십진수로 변환

n=11, m=24에 대한 출력해야 36.8

n=1, m=3에 대한 출력해야 20

n=184, m=5에 대한 출력해야

n=100, m=5에 대한 0.458(3)

n=100, m=7 출력을 사용해야합니다. 14.(285714)

내 프로그램이 마지막 분수 (100/7)에 실패했습니다. 내가 도대체 ​​뭘 잘못하고있는 겁니까? 누군가 나를 도울 수 있습니까? 한 자리 반복에 대한

Program fraction2decimal(output); 
var n,m,remainder: integer; 

begin 
    read(n,m); 
    d := 0; 
    write (n div m); 
    remainder := n mod m; 
    if remainder <> 0 then write('.'); 
    while remainder <> 0 do 
    begin 
    if remainder = (remainder*10 mod m) then write('('); 
    write (remainder*10 div m); 
    if remainder = (remainder*10 mod m) then begin 
     write(')'); 
     break; 
    end; 
end; 
    remainder := remainder*10 mod m; 
end. 

답변

2

if remainder = (remainder*10 mod m) 

행 전용 검사 :

내 코드입니다. 여러 자릿수의 반복 숫자를 확인해야합니다. 분명히 100/7이 바로 그 운동에 추가되었습니다.