Thread: Any 1 can write a C cording for this problem plz post hear..

  1. #1
    Registered User
    Join Date
    Aug 2007
    Posts
    5

    Any 1 can write a C cording for this problem plz post hear..

    A partition of a positive integer N is a sequence of positive integers that sum to N. c cording 4 non increasing partition of n....


    Eg If n = 4


    output like

    4
    3 1
    2 2
    2 1 1
    1 1 1 1

  2. #2
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,057
    Is this homework? http://cboard.cprogramming.com/annou...t.php?f=4&a=39

    Have you actually tried this? Do you have anything to show for it?

    [edit] A recursive function would work well for this, although I'm sure you could implement an iterative version as well. [/edit]
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  3. #3
    Registered User
    Join Date
    Aug 2007
    Posts
    5
    Quote Originally Posted by dwks View Post
    Is this homework? http://cboard.cprogramming.com/annou...t.php?f=4&a=39

    Have you actually tried this? Do you have anything to show for it?

    [edit] A recursive function would work well for this, although I'm sure you could implement an iterative version as well. [/edit]
    No dat s nt home work...ill try to do it by using iterative manner bt no idea to do dat...

    if any 1 cn gimme a psedocode dats more dan enough... den i cn get an idea of it...

  4. #4
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,057
    Typing proper english takes only a few more seconds of your time, if that, but it makes your post give a better impression, and might save your readers some time. Really. Try it sometime.

    An iterative solution is probably possible, but it would be more complicated than a recursive solution. First of all, "iterative" means with loops, like for or while loops, which recursive is a function that calls itself. Recursion isn't as hard as it sounds.

    I wrote up a recursive solution, but I deleted it because I wasn't sure if you wanted to see it or not . . . anyway, what it did was basically this:
    Code:
    if max == 0:
        print "\n";
    else:
        for x in (1..max):
            print x;
            recurs(max-x);
    Think about it. I think it would work, though I'm not sure my logic is sound or that I converted my code into pseudo-[python] correctly.
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  5. #5
    Registered User
    Join Date
    Aug 2007
    Posts
    5
    its ok ill try....... ya i think recursive way is little bit easy to solve that problem....

  6. #6
    Registered User
    Join Date
    Jul 2006
    Posts
    162
    let's not respond to people who type like that here... they should keep that crap in counter-strike.

  7. #7
    Deathray Engineer MacGyver's Avatar
    Join Date
    Mar 2007
    Posts
    3,210
    Quote Originally Posted by simpleid View Post
    let's not respond to people who type like that here... they should keep that crap in counter-strike.
    wut u mean by dat? r u sayin only 1337 h4x0r skr1p7 k1dd13z talk lik dis?

    To the OP: http://catb.org/~esr/faqs/smart-questions.html

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 3
    Last Post: 03-04-2005, 02:46 PM
  2. Replies: 5
    Last Post: 02-08-2003, 07:42 PM
  3. Sorry for Illegal post, plz delete.
    By lfireteam destroyer in forum C++ Programming
    Replies: 0
    Last Post: 04-15-2002, 09:28 PM