Jump to content

Abundant, deficient and perfect number classifications: Difference between revisions

Initial FutureBasic task solution added
m (→‎{{header|Pascal}}: move to sub group ==={{header|Free Pascal}}===)
(Initial FutureBasic task solution added)
Line 2,587:
Abundant: 4953
</pre>
 
=={{header|FutureBasic}}==
<syntaxhighlight lang="futurebasic">
local fn SumProperDivisors( number as long ) as long
long i, result, sum = 0
if number < 2 then exit fn = 0
for i = 1 to number / 2
if number mod i == 0 then sum += i
next
result = sum
end fn = result
 
void local fn NumberCategories( limit as long )
long i, sum, deficient = 0, perfect = 0, abundant = 0
for i = 1 to limit
sum = fn SumProperDivisors(i)
if sum < i then deficient++ : continue
if sum == i then perfect++ : continue
abundant++
next
printf @"\nClassification of integers from 1 to %ld is:\n", limit
printf @"Deficient = %ld\nPerfect = %ld\nAbundant = %ld", deficient, perfect, abundant
printf @"-----------------\nTotal = %ld\n", deficient + perfect + abundant
end fn
 
CFTimeInterval t
t = fn CACurrentMediaTime
fn NumberCategories( 20000 )
printf @"Compute time: %.3f ms",(fn CACurrentMediaTime-t)*1000
 
HandleEvents
</syntaxhighlight>
{{output}}
<pre>
Classification of integers from 1 to 20000 is:
 
Deficient = 15043
Perfect = 4
Abundant = 4953
-----------------
Total = 20000
 
Compute time: 1761.443 ms
</pre>
 
 
=={{header|GFA Basic}}==
717

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.