Go4Expert

Go4Expert (http://www.go4expert.com/)
-   C (http://www.go4expert.com/forums/c/)
-   -   help me to solve this problem (http://www.go4expert.com/forums/help-solve-t6032/)

isurues 25Aug2007 14:17

help me to solve this problem
 
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

DaWei 25Aug2007 14:44

Re: help me to solve this problem
 
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.

isurues 25Aug2007 15:24

Re: help me to solve this problem
 
Quote:

Originally Posted by DaWei
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.

if can give me a C coding for this problem

DaWei 25Aug2007 15:30

Re: help me to solve this problem
 
Explain how you would go about solving this problem, mentally. We'll go from there.

isurues 25Aug2007 15:39

Re: help me to solve this problem
 
Quote:

Originally Posted by DaWei
Explain how you would go about solving this problem, mentally. We'll go from there.

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

shabbir 25Aug2007 22:25

Re: help me to solve this problem
 
Do you have any algorithm in mind to go about it?

isurues 25Aug2007 22:29

Re: help me to solve this problem
 
Quote:

Originally Posted by shabbir
Do you have any algorithm in mind to go about it?

i dont have any idea...

shabbir 25Aug2007 22:52

Re: help me to solve this problem
 
Quote:

Originally Posted by isurues
i dont have any idea...

As I can see its just a number split into numbers which sum up to the inputed number till all become one.

isurues 25Aug2007 22:57

Re: help me to solve this problem
 
Quote:

Originally Posted by shabbir
As I can see its just a number split into numbers which sum up to the inputed number till all become one.

ya thats according to the input n

isurues 25Aug2007 22:59

Re: help me to solve this problem
 
Quote:

Originally Posted by shabbir
As I can see its just a number split into numbers which sum up to the inputed number till all become one.

Ya need all the possible number which v can split


All times are GMT +5.5. The time now is 19:21.