Hi:
This is a version of your code with 2 bug fixes. However the algorithm you are using is not correct. As you will see it is producing false positives. Perhaps I missed a bug, or there is no accepted solution?
The changes I made may help you to make some progress.
Garvan
EDITED 2004-10-13
I think I found the last bug. The closing bracket of the "for" loop was in the wrong place. I updated the code below.
Garvan
//====================================
#include <stdio.h>
#include <math.h>
int perfect(int num);
int factor(int num);
int main()
{
int i;
i=2;
while (i<10000) /*Display perfect numbers between 0 and 10000*/
{
if( perfect (i) )
{
printf("%d the factors of the number is\n",i); /*This is to display the perfect number and its factor */
factor (i);
printf("\n");
}
i++;
}
return 0;
}
int perfect(int num)
{
int addition=0;
int j=1;
int Maximumlimit;
Maximumlimit= num/2;
for(j=1; j<=Maximumlimit; j++)
{
if (num%j==0)
{
addition +=j;
}
}
if(addition==num)
{
return 1;
}
else
{
return 0;
}
}
int factor(int num)
{
int j=1;
int Maximumlimit=num/2;
do
{
if(num%j==0)
{
printf("%d ",j);
}
j++;
}while(j<=Maximumlimit);
return 0;
}