My son & I are throughly frustrated....we've gotten this far on a program for the perfect numbers between 1 - 100, but have hit many dead ends. So far, the output is "3206" - but in the many attempts have had outputs of 0, 1, blank, and a list of 100 zeros with a 2 at the end. I know that it's something simple, but sometimes the more you mess with something, the harder it is to spot the obvious mistake. If someone would be kind enough to point me in the right direction, so that I can point my kid in the right direction, I would truly appreciate it!
Code:
/*This program displays all the perfect numbers in the range of 1-100 */
#include<stdio.h>
#include<math.h>
#include"genlib.h"
#include"simpio.h"
int perfect(int num);
main()
{
int num, p;
printf ("the perfect numbers in the range of 1 - 100 are:\n\n");
for (num=2; num<=100; num+=2); /*all known perfect numbers below the
value of 10 to the 300th power are
even*/
p = perfect (num);
printf ("%d\n", p);
}
int perfect(int num)
{
int i, sum, p;
for (i=2; i<num; i++)
{
if (num%i == 0)
{
sum += num;
}
if (sum == num)
{
sum = p;
}
}
return (p);
}