Abundant, deficient and perfect number classifications: Difference between revisions

m (→‎{{header|Sidef}}: minor code fix)
Line 1,659:
perfect: 4
took 0.802559 seconds
</pre>
 
=={{header|PureBasic}}==
<lang PureBasic>
EnableExplicit
 
Procedure.i SumProperDivisors(Number)
If Number < 2 : ProcedureReturn 0 : EndIf
Protected i, sum = 0
For i = 1 To Number / 2
If Number % i = 0
sum + i
EndIf
Next
ProcedureReturn sum
EndProcedure
Define n, sum, deficient, perfect, abundant
 
If OpenConsole()
For n = 1 To 20000
sum = SumProperDivisors(n)
If sum < n
deficient + 1
ElseIf sum = n
perfect + 1
Else
abundant + 1
EndIf
Next
PrintN("The breakdown for the numbers 1 to 20,000 is as follows : ")
PrintN("")
PrintN("Deficient = " + deficient)
PrintN("Pefect = " + perfect)
PrintN("Abundant = " + abundant)
PrintN("")
PrintN("Press any key to close the console")
Repeat: Delay(10) : Until Inkey() <> ""
CloseConsole()
EndIf
</lang>
 
{{out}}
<pre>
The breakdown for the numbers 1 to 20,000 is as follows :
 
Deficient = 15043
Pefect = 4
Abundant = 4953
</pre>
 
9,492

edits