The QBasic Forum      Other Subforums, Links and Downloads
 Return to Index  

I should have stayed anonymous

March 11 2009 at 6:06 PM
lawgin  (no login)


Response to Why that answer and not the exact

I am not brazen enough to try and change the rules again, so I have to accept your exact answer of 3858/3125 as the correct one. Here is my code which does minimize the numerator and denominator (I think).

INPUT "Enter Decimal"; d$
p = LEN(d$) - INSTR(d$, ".") + 1
d1 = VAL(d$)
wp = INT(d1)
dp = d1 - wp
DO
m = m + 1
x1 = m * dp
x2 = CLNG(x1)
dx = ABS(x1 - x2)
IF dx < min THEN min = dx: y = m: d2 = (CLNG(y * dp) + y * wp) / y
LOOP UNTIL ABS(d2 - d1) < 1 / 10 ^ p
PRINT d1; "="; CLNG(y * dp) + y * wp; "/"; y
END

 
 Respond to this message   
Responses