Thread: Need some ideas on gerating divisors.

  1. #1
    Registered User
    Join Date
    Oct 2016
    Posts
    7

    Need some ideas on gerating divisors.

    Recently we got an group assignment in our class. This is totally different than what we have been done is class so far. We have no idea how to start this this off. Assignment is
    "Write a program that reads two integers and prints the number in the given range that has the most divisors, as well as its number of divisors.
    Example:
    Enter two integers: 20 100
    60 with 10 divisors has the largest number of divisors."

    This is a beginning class. so far we have learned up to loops and now doing functions. Any help will be appreciated. Thaks

  2. #2
    Registered User MutantJohn's Avatar
    Join Date
    Feb 2013
    Posts
    2,665
    So, you know something is a divisor of something else if the modulo is 0. You also don't need to go past n /2 numbers to determine this (this part I'm unsure of lol). So basically, for each number, just use a dumb for-loop and then iterate and if the modulo of your target number with the index of the loop is 0, then it's a divisor.

    Por ejemplo with numero 60:
    Code:
    int const num{ 60 };
    
    for (int i = 2; i < num; ++i) {
      if (num % i == 0) {
        std::cout << i << " is a divisor\n";
      }
    }

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Help w/ divisors by 4
    By BB89 in forum C Programming
    Replies: 7
    Last Post: 06-25-2010, 09:06 AM
  2. Perfect number and divisors
    By Lissa in forum C Programming
    Replies: 31
    Last Post: 10-24-2008, 01:36 PM
  3. display of divisors
    By Lissa in forum C++ Programming
    Replies: 3
    Last Post: 10-19-2008, 11:20 AM
  4. Finding divisors
    By xbusterx in forum C++ Programming
    Replies: 20
    Last Post: 10-04-2008, 08:08 PM
  5. Help with Computing Divisors
    By MrPink in forum C++ Programming
    Replies: 2
    Last Post: 09-30-2005, 07:35 PM

Tags for this Thread