Abundant, deficient and perfect number classifications: Difference between revisions

→‎{{header|ALGOL 68}}: Simplified - the task doesn't require examples of each type anymore
(→‎{{header|ALGOL 68}}: Simplified - the task doesn't require examples of each type anymore)
Line 796:
INT deficient count := 0;
INT perfect count := 0;
INT abundant example := 0;
INT deficient example := 0;
INT perfect example := 0;
INT max number = 20 000;
# construct a table of the proper divisor sums #
Line 809 ⟶ 806:
# classify the numbers #
FOR n TO max number DO
IF INT pd sum = pds[ n ];
IF pd sum < n THEN
THEN deficient count +:= 1
ELIF pd sum = n THEN
# have a deficient number #
deficientperfect count +:= 1;
deficient example := n
ELIF pd sum = n
THEN
# have a perfect number #
perfect count +:= 1;
perfect example := n
ELSE # pd sum > n #
# have an abundant number count +:= #1
abundant count +:= 1;
abundant example := n
FI
OD;
print( ( "abundant ", whole( abundant count, 0 ), newline ) +:= 1);
# displays the classification, count and example #
showprint( result( "deficient ", whole( deficient count, deficient0 ), newline example) );
PROC show result = ( STRING classification, INT count, example )VOID:
print( ( "perfect ", whole( perfect count, 0 ), newline ) +:= 1;)
print( ( "There are "
END
, whole( count, -8 )
END</syntaxhighlight>
, " "
, classification
, " numbers up to "
, whole( max number, 0 )
, " e.g.: "
, whole( example, 0 )
, newline
)
);
 
# show how many of each type of number there are and an example #
show result( "abundant ", abundant count, abundant example );
show result( "deficient", deficient count, deficient example );
show result( "perfect ", perfect count, perfect example )
END</syntaxhighlight>
{{out}}
<pre>
abundant 4953
There are 4953 abundant numbers up to 20000 e.g.: 20000
deficient 15043
There are 15043 deficient numbers up to 20000 e.g.: 19999
perfect 4
There are 4 perfect numbers up to 20000 e.g.: 8128
</pre>
 
3,032

edits