### Search

 Search WWW Search DelphiForFun.org

As of October, 2016, Embarcadero is offering a free release of Delphi (Delphi 10.1 Berlin Starter Edition ).     There are a few restrictions, but it is a welcome step toward making more programmers aware of the joys of Delphi.  They do say "Offer may be withdrawn at any time", so don't delay if you want to check it out.  Please use the feedback link to let me know if the link stops working.

Support DFF - Shop

If you shop at Amazon anyway,  consider using this link.

We receive a few cents from each purchase.  Thanks

### Support DFF - Donate

If you benefit from the website,  in terms of knowledge, entertainment value, or something otherwise useful, consider making a donation via PayPal  to help defray the costs.  (No PayPal account necessary to donate via credit card.)  Transaction is secure.

Mensa® Daily Puzzlers

For over 15 years Mensa Page-A-Day calendars have provided several puzzles a year for my programming pleasure.  Coding "solvers" is most fun, but many programs also allow user solving, convenient for "fill in the blanks" type.  Below are Amazon  links to the two most recent years.

(Hint: If you can wait, current year calendars are usually on sale in January.)

### Contact

 Search DelphiForFun.org only

## Beginner - Recurring Quotient

### Problem Statement

If you divide a 5 digit number by the sum of its digits, some divide evenly, some do not.  For all 5 digit number between 10,000 and 99,999 that do divide evenly by the sum of their digits, what quotient occurs most often?

Source: Math and Logic Puzzles for PC Enthusiasts, J. J. Clessa, Dover Books.

### Defining the program

Here's the plan - I'm pretty sure that the largest quotient will be 10,000 (when we divide 10,000 by 1).  So let's just set up an array to hold each of the 10,000 possible counts of quotient occurrences.  In other words, when we finish, Counts[100] will contain the number of times that the quotient 100 occurred, etc.  Then all we have to do is scan this array for the largest value  and display it.

Now all we have to do is figure out how to extract the digits from a number, add them up and test if they divide the number evenly.   One good way to do this is to use the mod operation which returns the remainder when one number is divider by another (mod stands for modulo).  In this case, n mod 10 will return the lowest level (units position) digit of n.  If we then divide n by 10 dropping any remainder, we can apply the mod function again and get the 10s digit, etc.  Luckily the integer divide function  div does exactly this -  divides one integer by another and returns the integer part of the quotient.

You will easily  find the loop that accomplishes this in the source code.  There are only 36 lines of user written code here!