Since I am terrible at summarizing here is what I need to do
"Write a function - maxDivs() - that takes two integers such as low and high and assigns the integer that has the largest number of divisors among all the integers that lie between low and high to an output parameter - num - and the number of divisors of num to another output parameter - divs. For example, if low and high are 20 and 50, the function assigns 48 to num since 48 has the largest number of divisors between 20 and 50 and assigns 8 to divs since 48 has 8 divisors - more than any other in the 20-50 range.
Write another function - numDivs() - that takes an integer as its only parameter and returns its number of divisors. For example, if its input parameter is 24, it returns 6 as its number of divisors.
Write a main program that reads two integers for low and high and passes them to maxDivs() function. maxDivs() function in turn gets the number of divisors for each integer between low and high by calling numDivs() function for each integer in the range.
Print both the integer with the largest number of divisors and the number of divisors it has, as output by maxDivs(), in main."
I'm unsure on how to properly do the maxDivs function currently. I believe everything else to be ok.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
|
#include <iostream>
using namespace std;
int maxdivs(int num, int divs);
int numdivs(int);
int main() // also will become void(int num, int divs)
{
int max, min;
cout << "input the lowest number. ";
cin >> min;
cout << "input the highest number. ";
cin >> max;
maxdivs(min, max);
}
int maxdivs(int num, int divs)
{
int low, high;
for (int i=2;i<=high;i++)
if (low%i==0)
{
cout << low;
low++;
}
}
int numdivs(int div)
{
int div;
int amount;
amount = 0;
cout << "put number ";
cin >> div;
for (int i=2;i<div;i++)
{
if (div%i==0)
amount++;
}
cout << amount;
return amount;
}
|