I am new to C programming and trying to build a c program that can calculate perfect number from 1 to 10000, perfect number is like....1+2+3=6, 1+2+4+7+14=28....

here are my codes

Code:
```#include <stdio.h>
#include <math.h>
#define max_n 7.0

int
main(void)
{
double n;
int number;
for (n=0;n<max_n;n+=1)
{

number = pow(2.0,n-1.0)* (pow(2.0,n)-1.0);

if (number>1 && number <10000)
{

printf("The perfect number is &#37;d.\n", number);
}
else
{
printf("System Error");
}
return (0);
}
}```

2. I'm still not sure I get the concept of a "perfect" number. What exactly are you trying to do here?

Edit: Oh! I think I see now . . .

Code:
```#include <stdio.h>
#include <math.h>

#define MAX_N 7.0

int main(void)
{
double n;
int number;

for (n=0; n<MAX_N; n += 1)
{
number = pow(2.0,n-1.0)* (pow(2.0,n)-1.0);

if ((number > 1) && (number < 10000))
{
printf("The perfect number is &#37;d.\n", number);
}
else
{
printf("System Error");
}
}

return 0;
}```
Start by indenting your code properly. And move the return 0 out of the for loop.

Here is my output I am getting:
Code:
```System ErrorSystem ErrorThe perfect number is 6.
The perfect number is 28.
The perfect number is 120.
The perfect number is 496.
The perfect number is 2016.```

3. Ok, so a few things that are wrong with your code:
1. You return inside the for-loop.
2. You do NOT return at the end of main [which of course matters little if you return "early" every time].
3. It is not actually giving perfect numbers [after fixing the above] since it doesn't make sure that n is a prime number (in fact, it needs to be a Mersenne prime) . See: http://en.wikipedia.org/wiki/Perfect_number

--
Mats