Anonymous user
Perfect numbers: Difference between revisions
Added BASIC
m (→{{header|Java}}: Typo) |
(Added BASIC) |
||
Line 2:
A number is perfect if the sum of its factors is equal to twice the number. An equivalent condition is that <tt>n</tt> is perfect if the sum of <tt>n</tt>'s factors that are less than <tt>n</tt> is equal to <tt>n</tt>.
=={{header|BASIC}}==
{{works with|QuickBasic|4.5}}
<qbasic>FUNCTION perf(n)
sum = 0
for i = 1 to n - 1
IF n MOD i = 0 THEN
sum = sum + i
END IF
NEXT i
IF sum = n THEN
perf = 1
ELSE
perf = 0
END IF
END FUNCTION</qbasic>
=={{header|Java}}==
|