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
14 Réponses
+ 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.
+ 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.
+ 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.
+ 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? 😉
+ 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;
}
+ 1
thank you veryy much)))
0
i do not know where to start
0
help me please
0
can you write a programm pleasee
0
thank you very much
0
i do not know this language of programming
0
i need in program on C++)
0
please