How to resolve the algorithm Proper divisors step by step in the FreeBASIC programming language

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Proper divisors step by step in the FreeBASIC programming language

Table of Contents

Problem Statement

The   proper divisors   of a positive integer N are those numbers, other than N itself, that divide N without remainder. For N > 1 they will always include 1,   but for N == 1 there are no proper divisors.

The proper divisors of     6     are   1, 2, and 3. The proper divisors of   100   are   1, 2, 4, 5, 10, 20, 25, and 50.

Show all output here.

Let's start with the solution:

Step by Step solution about How to resolve the algorithm Proper divisors step by step in the FreeBASIC programming language

Source code in the freebasic programming language

' 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

  

You may also check:How to resolve the algorithm Address of a variable step by step in the Component Pascal programming language
You may also check:How to resolve the algorithm World Cup group stage step by step in the Wren programming language
You may also check:How to resolve the algorithm Hello world/Standard error step by step in the Sidef programming language
You may also check:How to resolve the algorithm Magic squares of doubly even order step by step in the PARI/GP programming language
You may also check:How to resolve the algorithm Perlin noise step by step in the Pascal programming language