1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

help me to solve this problem

Discussion in 'C' started by isurues, Aug 25, 2007.

  1. isurues

    isurues New Member

    Joined:
    Aug 25, 2007
    Messages:
    6
    Likes Received:
    0
    Trophy Points:
    0
    A partition of a positive integer n is a sequence of positive integers that sum to n. Write an algorithm in psedocode and then implement the algorithm (in C) to print all non-increasing partitions of n.

    eg. If n=4
    4
    3 1
    2 2
    2 1 1
    1 1 1 1
     
  2. DaWei

    DaWei New Member

    Joined:
    Dec 6, 2006
    Messages:
    835
    Likes Received:
    5
    Trophy Points:
    0
    Occupation:
    Semi-retired EE
    Location:
    Texan now in Central NY
    Home Page:
    Well, look at your example. There's a pattern there. Use that to devise your algorithm. This is your problem to solve -- it's how you learn. We're here to help you with the code problems.
     
  3. isurues

    isurues New Member

    Joined:
    Aug 25, 2007
    Messages:
    6
    Likes Received:
    0
    Trophy Points:
    0
    if can give me a C coding for this problem
     
  4. DaWei

    DaWei New Member

    Joined:
    Dec 6, 2006
    Messages:
    835
    Likes Received:
    5
    Trophy Points:
    0
    Occupation:
    Semi-retired EE
    Location:
    Texan now in Central NY
    Home Page:
    Explain how you would go about solving this problem, mentally. We'll go from there.
     
  5. isurues

    isurues New Member

    Joined:
    Aug 25, 2007
    Messages:
    6
    Likes Received:
    0
    Trophy Points:
    0
    Eg n = 5
    5
    4 1 (4+1 = 5)
    3 2 (3+2 = 5)
    3 1 1 (3+1+1 =5)
    2 1 1 1 (2+1+1+1 = 5)
    1 1 1 1 1 (1+1+1+1+1 = 5)
    thats how we can calculate it ...i think we have to use recursive function
     
  6. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,285
    Likes Received:
    364
    Trophy Points:
    83
    Do you have any algorithm in mind to go about it?
     
  7. isurues

    isurues New Member

    Joined:
    Aug 25, 2007
    Messages:
    6
    Likes Received:
    0
    Trophy Points:
    0
    i dont have any idea...
     
  8. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,285
    Likes Received:
    364
    Trophy Points:
    83
    As I can see its just a number split into numbers which sum up to the inputed number till all become one.
     
  9. isurues

    isurues New Member

    Joined:
    Aug 25, 2007
    Messages:
    6
    Likes Received:
    0
    Trophy Points:
    0
    ya thats according to the input n
     
  10. isurues

    isurues New Member

    Joined:
    Aug 25, 2007
    Messages:
    6
    Likes Received:
    0
    Trophy Points:
    0
    Ya need all the possible number which v can split
     
  11. madhu_

    madhu_ New Member

    Joined:
    Sep 22, 2009
    Messages:
    2
    Likes Received:
    0
    Trophy Points:
    0

    can u give me the code for this algorithm or tell me how to implement it.
     
  12. madhu_

    madhu_ New Member

    Joined:
    Sep 22, 2009
    Messages:
    2
    Likes Received:
    0
    Trophy Points:
    0
    can any one give coding for this problem??????
     

Share This Page