If all the irreducible fractions between 0 and 1, with denominators at most 99, are listed in ascending order, which two fractions would be before and after 11/21?
Determine which two fractions are adjacent to 34/87 in this listing.
45 / 86 ( .5232558139534884 )
11 / 21 ( .5238095238095238 )
43 / 82 ( .524390243902439 )
25 / 64 ( .390625 )
34 / 87 ( .3908045977011494 )
9 / 23 ( .391304347826087 )
from
DEFDBL A-Z
CLS
numGoal = 11: denGoal = 21: valgoal = numGoal / denGoal
lower = 0: upper = 1
FOR num = 1 TO 98
FOR den = num + 1 TO 99
IF num <> numGoal OR den <> denGoal THEN
value = num / den
IF value > lower AND value < valgoal THEN
lower = value
lowNum = num: lowDen = den
EXIT FOR
ELSEIF value < upper AND value > valgoal THEN
upper = value
highNum = num: highDen = den
EXIT FOR
ELSEIF value < lower THEN EXIT FOR
END IF
END IF
NEXT
NEXT
PRINT lowNum; "/"; lowDen; "("; lower; ")"
PRINT numGoal; "/"; denGoal; "("; valgoal; ")"
PRINT highNum; "/"; highDen; "("; upper; ")"
numGoal = 34: denGoal = 87: valgoal = numGoal / denGoal
lower = 0: upper = 1
FOR num = 1 TO 98
FOR den = num + 1 TO 99
IF num <> numGoal OR den <> denGoal THEN
value = num / den
IF value > lower AND value < valgoal THEN
lower = value
lowNum = num: lowDen = den
EXIT FOR
ELSEIF value < upper AND value > valgoal THEN
upper = value
highNum = num: highDen = den
EXIT FOR
ELSEIF value < lower THEN EXIT FOR
END IF
END IF
NEXT
NEXT
PRINT
PRINT lowNum; "/"; lowDen; "("; lower; ")"
PRINT numGoal; "/"; denGoal; "("; valgoal; ")"
PRINT highNum; "/"; highDen; "("; upper; ")"
|
Posted by Charlie
on 2004-07-23 11:19:08 |