View Single Post
Old Jan 7th, 2007, 8:53 AM   #13
gamerfelipe
Newbie
 
Join Date: Jan 2007
Location: Hershey, the sweetest place on earth
Posts: 19
Rep Power: 0 gamerfelipe is on a distinguished road
Thanks Guys! Here we go:

#include <iostream.h>

int divisor_count (int n);

int main()
{    
     int x;
     int divisors;
     int max_divs = 0;
     int max_num = 0;
     int last_num = 1000;

      for (x = 1; x <= last_num; x++)
      { 
          divisors = divisor_count(x);
          if (divisors > max_divs)
          {
             max_num = x;
             max_divs = divisors;
          }
      }
      cout << "The number with the most divisors is " << max_num << endl;
      return 0;
} 

int divisor_count (int n)
{
    int count = 1;

    for ( int i = 2; i <= n; i++ )
    {
        if ( n % i == 0 )
            ++count;
    }
    return count;
}
gamerfelipe is offline   Reply With Quote