Jump to content

Perfect numbers: Difference between revisions

Remove unnecessary iteration and logically redundant test (if [sum == 2 * num] then [sum - num == num] for all positive num anyway).
(Add lambda version)
(Remove unnecessary iteration and logically redundant test (if [sum == 2 * num] then [sum - num == num] for all positive num anyway).)
Line 154:
{
int sum = 0;
for (int i = 1; i < num + 1; i++)
{
if (num % i == 0)
Line 160:
}
 
return ((sum == 2 * num || (sum - num == num)));
}
</lang>
Anonymous user
Cookies help us deliver our services. By using our services, you agree to our use of cookies.