Hey everyone hope all is well! Its that time of the week again and Im stuck already! lol I think I have gotten far this time, but still cant get things right.
The project calls for a program to find all perfect numbers between 2 and 10,000. The program will determine whether a number is perfect by calling the function "isperfect". The function returns 1 if x is perfect and 0 if not. Print each perfect number on a seperate line along with its expansion as a sum of factors. The factors should appear in ascending order. For example the first line should read.
6 = 1 + 2 + 3
So I have managed to get the perfect number. Im not sure how to print out the sum of factors because thats not really how I wrote it. So where should I go from here?
Code:
#include<stdio.h>
int isperfect(int x)
{
int total=0,i=0;
for (i=0;i<(x/2);i++)
{
if (!(x%(i+1)))
{
total+=i+1;
}
}
if (total==x) return 1;
return 0;
}
int main(void)
{
int a=2,b=10000;
for(; a<b; a++)
if(isperfect(a))
printf("%d TEST TEST\n",a,);
return 0;
}