Computing.Net > Forums > Programming > Need help with C++ program

Need help with C++ program

Reply to Message Icon

Original Message
Name: Adrenalyne
Date: January 14, 2003 at 12:55:56 Pacific
Subject: Need help with C++ program
OS: XP
CPU/Ram: /
Comment:

Hi.
I'm currently learning C++ programming and I have problems coding a program.
I need to write a program that finds the integer from 1 to 1000 with the most divisors that produce no remainder.
For example, the integer 60 has 12 divisors that produce no remainder.
They are 1,2,3,4,5,6,10,12,15,20,30,60.

Can anyone help code this program? Thanks in advance.



Report Offensive Message For Removal


Response Number 1
Name: JohnGa
Date: January 14, 2003 at 14:56:51 Pacific
Reply: (edit)

Lotsa loops :D

loop from 1 to 1000, duh. Then for each one, start at the number you are at, and count down from it. At each number counting down, and keep subtracting the number(lets call it "test") from the original. If you get to a point where the test is bigger than the remainder, but its not 0, then it doesnt work. If it does work, however, increase a counter for that number that counts the number of divisors. Once test reaches 0, then compare the number of divisors to a set of 2 variables you have: One for the current record number, and another for the number of divisors that number has. If your test is greater, and set it as the current record. And once the parent loop reachers 1000, your done, and output the result.

Hope it helps, lol


Report Offensive Follow Up For Removal

Response Number 2
Name: Ronin1
Date: January 14, 2003 at 17:27:23 Pacific
Reply: (edit)

Yea, sure... lots of loops too :P

#include [iostream.h]

int main(void)
{
long count, input, j, i, values[100] = { 0 };

cout [[ "Enter a number: ";
cin ]] input;

j = 0;
count = 0;

for(i=1; i [= input; i++)
{
if((input % i) == 0)
{
values[j++] = i;
count++;
}
}

cout [[ endl [[ "The number " [[ input
[[ ", has " [[ count [[ " factors:" [[ endl [[ endl ;

for(j = 0; values[j] != '\0'; j++)
cout [[ values[j] << ' ';

return 0;

}

or something along those lines. :)


Report Offensive Follow Up For Removal

Response Number 3
Name: Happy Helper
Date: January 14, 2003 at 17:47:52 Pacific
Reply: (edit)

#include

int main()
{
for(int m = 1; m < 1001; m++) {

cout 0)

if(m % n-- == 0)

cout << n + 1 << " ";

cout << "\n\n";
}
return 0;
}


Report Offensive Follow Up For Removal

Response Number 4
Name: happy helper
Date: January 14, 2003 at 17:55:46 Pacific
Reply: (edit)

#include
int main()
{
for(int m = 1; m 0)
if(m % n-- == 0)
cout << n + 1 << " ";
cout << "\n\n";
}
return 0;
}

:-)


Report Offensive Follow Up For Removal

Response Number 5
Name: Adrenalyne
Date: January 15, 2003 at 13:33:03 Pacific
Reply: (edit)

Thank you guys so much!!!!!!!!!


Report Offensive Follow Up For Removal


Response Number 6
Name: JohnGa
Date: January 16, 2003 at 17:43:07 Pacific
Reply: (edit)

ya considering we wrote the code for u..now go out and learn it c++ haha :-p


Report Offensive Follow Up For Removal






Use following form to reply to current message:

   Name: From My Computing.Net Settings
 E-Mail: From My Computing.Net Settings

Subject: Need help with C++ program

Comments:

 


  Homepage URL (*): 
Homepage Title (*): 
         Image URL: 
 
Data Recovery Software




Have you ever used OpenOffice?

Yes, as my main suite.
Yes, occationally.
Yes, but only once.
No, never.


View Results

Poll Finishes Today.
Discuss in The Lounge