0

in the range from 1 to 1000, find 3 numbers with the greatest number of dividers

need to write a program c++. help please

22nd Dec 2017, 9:19 PM
zama
13 Respostas
+ 3
By dividers, do u mean factors? If so: Make an array for the top 3 numbers. Make an array for their numbers of factors. For loop doing the following for each number up to 1000: For loop for all numbers up to it: Use modulus to see if divisible If so, change a number saying number of factors by 1 If the number of factors is greater than any of the numbers in the array for numbers of factors, replace with that and replace that item of the other array with the number. After that, just have to organize these from most to least.
22nd Dec 2017, 9:38 PM
Jacob Pembleton
Jacob Pembleton - avatar
+ 2
1. Write a function that returns the number of dividers of its parameter. 2. Create an array of 1000 integers and fill it with the results of your function, whose parameters will be indexes of array. 3. Find maximum in the array, print it's index and then write 0 to that element. Do it 3 times. The problem is solved.
22nd Dec 2017, 9:33 PM
Petr Leliaev
Petr Leliaev - avatar
+ 2
90 180 360 540 720 900 did you know that 360 for degrees was a good number because of how many numbers can divide in to it evenly.
22nd Dec 2017, 10:15 PM
Dick Tracy
Dick Tracy - avatar
+ 1
@zama You already have the idea of how to do it, as suggested by @Petr Leliaev and @Jacob Pembleton. If you cannot write it, then post a code here with your attempt so we can fix it. Nobody is going to help you write a code; otherwise what's the point of learning? 😉
22nd Dec 2017, 10:01 PM
blackcat1111
blackcat1111 - avatar
+ 1
#include <iostream> using namespace std; int main() { int nums[3] = {0, 0, 0}; int fact[3] = {0, 0, 0}; int fc; for(int a = 1; a <= 1000; a++) { fc = 0; for(int b = 1; b < a; b++) { int mod = a % b; if (mod == 0) { fc++; } } for(int c = 0; c < 3; c++) { if (fc > fact[c]) { fact[c] = fc; nums[c] = a; break; } } } cout << nums[0] << ": " << fact[0] << endl; cout << nums[1] << ": " << fact[1] << endl; cout << nums[2] << ": " << fact[2] << endl; return 0; }
22nd Dec 2017, 10:06 PM
Jacob Pembleton
Jacob Pembleton - avatar
+ 1
thank you veryy much)))
22nd Dec 2017, 10:07 PM
zama
0
i do not know where to start
22nd Dec 2017, 9:24 PM
zama
0
help me please
22nd Dec 2017, 9:24 PM
zama
0
can you write a programm pleasee
22nd Dec 2017, 9:36 PM
zama
0
thank you very much
22nd Dec 2017, 9:36 PM
zama
0
i do not know this language of programming
22nd Dec 2017, 9:37 PM
zama
0
i need in program on C++)
22nd Dec 2017, 9:45 PM
zama
0
please
22nd Dec 2017, 9:45 PM
zama