RosettaCodeData/Task/Proper-divisors/FreeBASIC/proper-divisors.basic

48 lines
998 B
Plaintext

' FreeBASIC v1.05.0 win64
Sub ListProperDivisors(limit As Integer)
If limit < 1 Then Return
For i As Integer = 1 To limit
Print Using "##"; i;
Print " ->";
If i = 1 Then
Print " (None)"
Continue For
End if
For j As Integer = 1 To i \ 2
If i Mod j = 0 Then Print " "; j;
Next j
Print
Next i
End Sub
Function CountProperDivisors(number As Integer) As Integer
If number < 2 Then Return 0
Dim count As Integer = 0
For i As Integer = 1 To number \ 2
If number Mod i = 0 Then count += 1
Next
Return count
End Function
Dim As Integer n, count, most = 1, maxCount = 0
Print "The proper divisors of the following numbers are :"
Print
ListProperDivisors(10)
For n As Integer = 2 To 20000
count = CountProperDivisors(n)
If count > maxCount Then
maxCount = count
most = n
EndIf
Next
Print
Print Str(most); " has the most proper divisors, namely"; maxCount
Print
Print "Press any key to exit the program"
Sleep
End