Last question on factors! - Programmers Heaven

#### Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

#### Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

# Last question on factors!

Posts: 12Member
All i need this to do now is to print out all the factors of the highest number and not include the highest number itself.

Been messing for a while but can't seem to quite get it right.

Any help would be appreciated

Thank you...

Here is my code

#include
int main(void)
{
int x,y,count=0,i,n;
for (x=2;x<=1000;++x)
{
i=0;
for (y=2;y<=1000;++y)
if (!(x%y)) ++i;
if (i>count) {n=x;count=i;}
}
printf("The integer %d has the most number of factors <=1000

",n);
printf("There are %d factors

",count);
printf("They are.................

");
return 0;

• Posts: 20Member
(pseudo code- try it yourself!!!)
I would say,
always save the last factor in a variable,
and if you found one thats higher, print it.

int curHighest = 0;

(Where do you print found factors)
There you can the do something like this:
if(curHighest > 0 && curHighest <= x%y)
{
printit("last %d", curHighest);
curHighest = x%y;
}

Then it wouldnt be printed the last time
youre passing...
There may be other ways to solve this program.