Beginner C/C++

Moderators: None (Apply to moderate this forum)
Number of threads: 5430
Number of posts: 16951

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
Last question on factors! Posted by anton19822 on 28 Jan 2006 at 1:38 PM
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 <stdio.h>
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\n\n",n);
printf("There are %d factors\n\n\n",count);
printf("They are.................\n\n\n");
return 0;
Report
Re: Last question on factors! Posted by sid_kkr on 28 Jan 2006 at 6:00 PM
(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.





 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.