Here is an integer only solution which is fairly compact, though almost totally naïve in its approach.
include <stdio.h>
#include <limits.h>
void main(int argc, char *argv[])
{
unsigned int p, f, t;
for (p = 2; p < UINT_MAX; p += 2) {
if (p == 6 || (p-1)/9*9 == (p-1)) {
for (t = 0, f = 1; f*f <= p; f++) {
if (p/f*f == p) {
t += f;
if (p/f != f && f!=1) t += p/f;
}
}
if (t == p)
printf ("%d\n", p);
}
}
}
I'm not sure that it's a terribly interesting problem at the level of "print the first 6" though. I agree with the others who have pointed out that once you have exploited some property of perfect numbers such as "they're probably even"
1 to avoid factorising each positive integer summing the factors and checking to see if that equals the original number you might as well go for the
printf("6\n28\n496\n8128\n33550336\n"); approach.
_Sin's code is actually more interesting, and much faster (Oh, BTW I don't want the Arduino either). It exploits the fact that 2
p-1(2
p-1) is an even perfect number if 2
p-1 is prime. the test for primeality in that code is a very simple one so, it's not as interesting as it could be.
If you want an interesting problem prove that 2
p-1(2
p-1) is perfect for p=25964951
[1] It has not been proven that there are no odd perfect numbers.