Proper divisors: Difference between revisions
Content added Content deleted
(Added various BASIC dialects (Chipmunk Basic and Gambas)) |
|||
Line 1,344: | Line 1,344: | ||
Igual que la entrada de FreeBASIC o PureBasic. |
Igual que la entrada de FreeBASIC o PureBasic. |
||
</pre> |
</pre> |
||
==={{header|Chipmunk Basic}}=== |
|||
{{trans|BASIC}} |
|||
{{works with|Chipmunk Basic|3.6.4}} |
|||
<syntaxhighlight lang="vbnet">100 cls |
|||
110 most = 1 |
|||
120 maxcount = 0 |
|||
130 print "The proper divisors of the following numbers are: ";chr$(10) |
|||
140 listproperdivisors(10) |
|||
150 for n = 2 to 20000 |
|||
160 rem It is extremely slow in this loop |
|||
170 count = countproperdivisors(n) |
|||
180 if count > maxcount then |
|||
190 maxcount = count |
|||
200 most = n |
|||
210 endif |
|||
220 next n |
|||
230 print |
|||
240 print most;" has the most proper divisors, namely ";maxcount |
|||
250 end |
|||
260 function countproperdivisors(number) |
|||
270 if number < 2 then countproperdivisors = 0 |
|||
280 count = 0 |
|||
290 for i = 1 to int(number/2) |
|||
300 if number mod i = 0 then count = count+1 |
|||
310 next i |
|||
320 countproperdivisors = count |
|||
330 end function |
|||
340 sub listproperdivisors(limit) |
|||
350 if limit < 1 then exit sub |
|||
360 for i = 1 to limit |
|||
370 print using "## ->";i; |
|||
380 if i = 1 then print " (None)"; |
|||
390 for j = 1 to int(i/2) |
|||
400 if i mod j = 0 then print " ";j; |
|||
410 next j |
|||
420 print |
|||
430 next i |
|||
440 end sub</syntaxhighlight> |
|||
==={{header|Craft Basic}}=== |
==={{header|Craft Basic}}=== |
||
Line 1,418: | Line 1,457: | ||
15120 has the most proper divisors, namely 79 |
15120 has the most proper divisors, namely 79 |
||
</pre> |
</pre> |
||
==={{header|Gambas}}=== |
|||
{{trans|FreeBASIC}} |
|||
<syntaxhighlight lang="vbnet">Sub ListProperDivisors(limit As Integer) |
|||
If limit < 1 Then Return |
|||
For i As Integer = 1 To limit |
|||
Print Format$(i, "## ->"); |
|||
If i = 1 Then |
|||
Print " (None)" |
|||
Continue |
|||
End If |
|||
For j As Integer = 1 To i \ 2 |
|||
If i Mod j = 0 Then Print " "; j; |
|||
Next |
|||
Print |
|||
Next |
|||
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 |
|||
Public Sub Main() |
|||
Dim n As Integer, count As Integer, most As Integer = 1, maxCount As Integer = 0 |
|||
Print "The proper divisors of the following numbers are: \n" |
|||
ListProperDivisors(10) |
|||
For n As Integer = 2 To 20000 |
|||
count = CountProperDivisors(n) |
|||
If count > maxCount Then |
|||
maxCount = count |
|||
most = n |
|||
End If |
|||
Next |
|||
Print |
|||
Print most; " has the most proper divisors, namely "; maxCount |
|||
End</syntaxhighlight> |
|||
{{out}} |
|||
<pre>Same as FreeBASIC entry.</pre> |
|||
==={{header|True BASIC}}=== |
==={{header|True BASIC}}=== |