home *** CD-ROM | disk | FTP | other *** search
/ Power Programming / powerprogramming1994.iso / progtool / pli / runpli1a.arc / FACTOR < prev    next >
Text File  |  1988-08-01  |  1KB  |  45 lines

  1.    PRINT(SYSPRINT,'Natural number?  ');
  2.    number_to_be_factored=GETINT(SYSIN);
  3.    PRINT(SYSPRINT,'Factors:');
  4.    PUTCRLF(SYSPRINT);
  5.    left_to_be_factored=number_to_be_factored;
  6.    upper_limit=left_to_be_factored;
  7.    finished=FALSE;
  8.    DO WHILE(! finished);
  9.      x2=(left_to_be_factored/upper_limit+upper_limit)/2;
  10.      IF x2 < upper_limit THEN
  11.        upper_limit=x2;
  12.      ELSE
  13.        finished=TRUE;
  14.    END;
  15.    possible_factor=2;
  16.    DO WHILE(possible_factor <= upper_limit);
  17.      quotient=left_to_be_factored/possible_factor;
  18.      product=quotient*possible_factor;
  19.      IF product = left_to_be_factored THEN
  20.        DO;
  21.          PRINT(SYSPRINT,'          ',possible_factor);
  22.          PUTCRLF(SYSPRINT);
  23.          left_to_be_factored=quotient;
  24.          upper_limit=left_to_be_factored;
  25.          finished=FALSE;
  26.          DO WHILE(! finished);
  27.            x2=(left_to_be_factored/upper_limit+upper_limit)/2;
  28.            IF x2 < upper_limit THEN
  29.              upper_limit=x2;
  30.            ELSE
  31.              finished=TRUE;
  32.          END;
  33.        END;
  34.      ELSE
  35.        IF possible_factor = 2 THEN
  36.          possible_factor=3;
  37.        ELSE
  38.          possible_factor=possible_factor+2;
  39.    END;
  40.    IF left_to_be_factored > 1 THEN
  41.      DO;
  42.        PRINT(SYSPRINT,'          ',left_to_be_factored);
  43.        PUTCRLF(SYSPRINT);
  44.      END;
  45.