Perfect numbers: Difference between revisions

no edit summary
No edit summary
Line 4,196:
 
<syntaxhighlight lang="smalltalk">1 to: 9000 do: [ :p | (p isPerfect) ifTrue: [ p printNl ] ]</syntaxhighlight>
 
=={{header|SparForte}}==
As a structured script.
<syntaxhighlight lang="ada">#!/usr/local/bin/spar
pragma annotate( summary, "perfect" );
pragma annotate( description, "In mathematics, a perfect number is a positive integer" );
pragma annotate( description, "that is the sum of its proper positive divisors, that is," );
pragma annotate( description, "the sum of the positive divisors excluding the number" );
pragma annotate( description, "itself." );
pragma annotate( see_also, "http://en.wikipedia.org/wiki/Perfect_number" );
pragma annotate( author, "Ken O. Burtch" );
pragma license( unrestricted );
 
pragma restriction( no_external_commands );
 
procedure perfect is
 
function is_perfect( n : positive ) return boolean is
total : natural := 0;
begin
for i in 1..n-1 loop
if n mod i = 0 then
total := @+i;
end if;
end loop;
return total = natural( n );
end is_perfect;
 
number : positive;
result : boolean;
begin
number := 6;
result := is_perfect( number );
put( number ) @ ( " : " ) @ ( result );
new_line;
 
number := 18;
result := is_perfect( number );
put( number ) @ ( " : " ) @ ( result );
new_line;
 
number := 28;
result := is_perfect( number );
put( number ) @ ( " : " ) @ ( result );
new_line;
 
end perfect;</syntaxhighlight>
 
=={{header|Swift}}==
76

edits