Apartitionof 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

Printable View

- 08-21-2007cbuwaAny 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 - 08-21-2007dwks
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] - 08-21-2007cbuwa
- 08-21-2007dwks
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);

- 08-21-2007cbuwa
its ok ill try....... ya i think recursive way is little bit easy to solve that problem....

- 08-21-2007simpleid
let's not respond to people who type like that here... they should keep that crap in counter-strike.

- 08-21-2007MacGyver
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