'===========================================================================
' Subject: Lowest common denom                Date: 07-01-01 (  :  )       
'  Author: Jerry Fielden                      Code: PBCC, PBDOS            
'  Origin:                                  Packet: PBCC.ABC
'===========================================================================

'This function will devide and give the answers with a fraction thats
'reduced to it's lowest common denominator. It works in PBDOS and
'PBCC . To test, try numbers like 5655\5423, 2345678\16 or fractions that
'can be reduced. 18144/45360 is reduced to 2/5 here. If the fraction can't
'be reduced, you will get it back as an answer.
'
'Author: Jerry Fielden
'Public Domain

DEFLNG a-z
FUNCTION PBMAIN  '  <----------------------- Dos, delete this line.

   LINE INPUT " Enter Numerator or dividend  "; Numerator$
   PRINT
   LINE INPUT " Enter Denomator or divisor   "; Denomator$
   num = VAL(Numerator$)
   denom = VAL(Denomator$)
   whole = FIX(num/denom)                    'Get whole number.
   IF num > denom THEN num = num MOD denom   'Get new numerator.

   DO                                               'Start reducing
      FOR x = 2 TO num
        IF num MOD x = 0 AND denom MOD x = 0 THEN   'See if done.
          num = num / x : denom = denom / x    'Maybe final answer .
          x = 1                        'reset FOR/Next for further reduction
          IF denom MOD num  = 0 THEN   'See if num will divide denom
             denom = denom / num       'reduce the denomator
             num = 1                   'reduce the numerator to 1.
             EXIT DO
          END IF
        END IF
      NEXT x
      EXIT DO
   LOOP

   PRINT
   PRINT " The answer is  ";
   IF whole THEN PRINT  STR$(whole);                 'Print whole number.
   IF num THEN PRINT " " + STR$(num) + "/" + LTRIM$(STR$(denom))' fraction.

   WAITKEY$   ' <--------------------------------- Dos, delete this line.

   END FUNCTION  ' <------------------------------ Dos, delete this line.


  
