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
This is a discussion on Any 1 can write a C cording for this problem plz post hear.. within the C Programming forums, part of the General Programming Boards category; A partition of a positive integer N is a sequence of positive integers that sum to N. c cording 4 ...
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
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.
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:
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.Code:if max == 0: print "\n"; else: for x in (1..max): print x; recurs(max-x);
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.
its ok ill try....... ya i think recursive way is little bit easy to solve that problem....
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