Calculus Computer Lab
Math 190


News

Lab Schedule

QuickBasic Notes

Fortran Notes

Tutor Room

Winplot Manual

Lab Home

xxxxxxxxxxxxxxxxxx

REM This program lists the divisors of a positive integer input by
REM the user. It outputs the list of divisors to a file. To see the
REM divisors you run the program and then open the file divisors.bas.
DEFLNG K, N
DEFSNG H
CLS
INPUT "What is your positive integer"; N

OPEN "divisors.bas" FOR OUTPUT AS #1

PRINT #1, "The divisors of"; N; "are:"
PRINT #1,

REM Find and PRINT the divisors.
K = 1
HALF = INT(N / 2)
count = 0
FOR K = 1 TO HALF
        IF N MOD K = 0 THEN
                PRINT #1, TAB(1 + 10 * (count MOD 8)); K;
                count = count + 1
        END IF
NEXT K
PRINT #1, TAB(1 + 10 * (count MOD 8)); N
count = count + 1

PRINT : PRINT "The integer"; N; "has"; count; "divisors."
PRINT : PRINT "Open the file 'divisors.bas' to see the list."
END