Thread: Combinations of given number that add up to X

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #4
    Registered User
    Join Date
    Sep 2012
    Posts
    357
    Use recursion ...

    The sets of 5 numbers (1 to 9) that add up to 28 include:
    : the number 1 plus the sets of 4 numbers (2 to 9) that add up to 27
    : the number 2 plus the sets of 4 numbers (3 to 9) that add up to 26
    ...
    : the number 5 plus the sets of 4 numbers (6 to 9) that add up to 22

    ...

    Note that I've made the numbers "go" into sets in ascending order; this way there is no repetition in the recursive calls.
    Last edited by qny; 12-02-2012 at 06:22 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 11
    Last Post: 03-18-2012, 03:05 PM
  2. All combinations
    By JonathanS in forum C Programming
    Replies: 38
    Last Post: 10-15-2011, 04:48 PM
  3. Generating number combinations
    By litzkrieg in forum C Programming
    Replies: 23
    Last Post: 03-01-2011, 11:25 AM
  4. computing the number of combinations
    By clover in forum C Programming
    Replies: 34
    Last Post: 06-06-2004, 01:12 PM
  5. Replies: 10
    Last Post: 01-07-2002, 04:03 PM

Tags for this Thread