Proper divisors: Difference between revisions
Added various BASIC dialects (Chipmunk Basic and Gambas)
(Added Easylang) |
(Added various BASIC dialects (Chipmunk Basic and Gambas)) |
||
(7 intermediate revisions by 4 users not shown) | |||
Line 1,252:
{{works with|QBasic|1.1}}
{{works with|QuickBasic|4.5}}
{{works with|QB64}}
<syntaxhighlight lang="qbasic">FUNCTION CountProperDivisors (number)
IF number < 2 THEN CountProperDivisors = 0
Line 1,343 ⟶ 1,344:
Igual que la entrada de FreeBASIC o PureBasic.
</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}}===
Line 1,417 ⟶ 1,457:
15120 has the most proper divisors, namely 79
</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}}===
Line 1,508 ⟶ 1,600:
Igual que la entrada de FreeBASIC o PureBasic.
</pre>
=={{header|BaCon}}==
Line 2,245 ⟶ 2,336:
=={{header|EasyLang}}==
<syntaxhighlight>
if n < 2
return [ ]
.
divs[] &= 1
Line 2,260 ⟶ 2,350:
.
.
return divs[]
.
for i to 10
print i & ":" & propdivs i
.
for i to 20000
d[] = propdivs i
if len d[] > max
max = len d[]
Line 2,275 ⟶ 2,364:
print maxi & " has " & max & " proper divisors."
</syntaxhighlight>
{{out}}
<pre>
1:[ ]
2:[ 1 ]
3:[ 1 ]
4:[ 1 2 ]
5:[ 1 ]
6:[ 1 2 3 ]
7:[ 1 ]
8:[ 1 2 4 ]
9:[ 1 3 ]
10:[ 1 2 5 ]
15120 has 79 proper divisors.
</pre>
=={{header|EchoLisp}}==
Line 2,795 ⟶ 2,898:
</pre>
=={{header|Frink}}==
Line 3,769 ⟶ 3,797:
=={{header|langur}}==
{{trans|Go}}
<syntaxhighlight lang="langur">
val
val cntproper = fn x: for[=0] i of x \ 2 { if x div i: _for += 1 }
val
if
for[=""]
_for ~=
}
}
writeln "The proper divisors of the following numbers are :"
writeln
var
var
for
val
if
} else if
}
}
writeln
writeln
</syntaxhighlight>
{{out}}
|