0

All right, I have an assignment for this introductory C++ class, and I'm sorry if this sounds silly, but I really don't know where to begin. We've just now gotten through the different kinds of loops and nested loops and that sort of thing, and my assignment is to write a program that finds the integer between 1 and 1000 with the most divisors that have no remainder. I asked my friend who does tech support for Microsoft (and thinks he knows everything) and went rambling on about storage arrays (or something...) and I really don't know what to do. I was looking for some kind of pattern to it, so that it wouldn't just be this huge loop with every single number 1 to 1000 in it.... but I could use some help or advice or something.

Thanks....

2
Contributors
1
Reply
2
Views
12 Years
Discussion Span
Last Post by Narue
0

First figure out how to count how many divisors are evenly divisible for single number. Once you have that, the solution presents itself as a variation of finding the maximum value in a set:

int main()
{
  int most = 1;
  int val = 1;

  for ( int i = 1; i <= 1000; i++ ) {
    int current = n_evenly_divisible ( i );

    if ( current > most ) {
      most = current;
      val = i;
    }
  }

  cout<< val <<" has "<< most <<" divisors evenly divisible"<<endl;
}

>and went rambling on about storage arrays (or something...)
Tech support people always overcomplicate things.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.