S
Sara
Hi,
I'm having a problem with my program and I think it stems from me not
understand how to call a function and return a int value to main.
What I have to do is create a program that runs through the numbers
and find the perfect numbers and list their factors. I cannot use
pointers or a table array or formulae. And I need to have a seperate
function from main doing all of this.
So far I have done the find the perfect numbers part, but its still in
main.
I don't understand how I can call the function from main and return
the perfect number and then list the factors.
I ended up finding the factors part, but that did all the numbers, not
just the perfect numbers. And as I tried fixing up my program, I lost
how I did that somehow.
So far I have this.
function
{
int number;
int factor;
int total;
for (number = 1; number <= MAX_LIMIT; ++number)
{
total = 0;
if (number%factor ==0)
{
total += factor;
}
}
if (number == total)
{
printf ("The perfect number is %5d ", number);
}
return (0);
}
I am just learning how to program in C, so I'm a basic beginner.
Any ideas or explanations will be appreciated.
Thanks
Sarah
I'm having a problem with my program and I think it stems from me not
understand how to call a function and return a int value to main.
What I have to do is create a program that runs through the numbers
and find the perfect numbers and list their factors. I cannot use
pointers or a table array or formulae. And I need to have a seperate
function from main doing all of this.
So far I have done the find the perfect numbers part, but its still in
main.
I don't understand how I can call the function from main and return
the perfect number and then list the factors.
I ended up finding the factors part, but that did all the numbers, not
just the perfect numbers. And as I tried fixing up my program, I lost
how I did that somehow.
So far I have this.
function
{
int number;
int factor;
int total;
for (number = 1; number <= MAX_LIMIT; ++number)
{
total = 0;
if (number%factor ==0)
{
total += factor;
}
}
if (number == total)
{
printf ("The perfect number is %5d ", number);
}
return (0);
}
I am just learning how to program in C, so I'm a basic beginner.
Any ideas or explanations will be appreciated.
Thanks
Sarah