# help me to solve this problem

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

1. ### isuruesNew Member

Joined:
Aug 25, 2007
Messages:
6
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. ### DaWeiNew Member

Joined:
Dec 6, 2006
Messages:
835
5
Trophy Points:
0
Occupation:
Semi-retired EE
Location:
Texan now in Central NY
http://www.daweidesigns.com
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. ### isuruesNew Member

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

4. ### DaWeiNew Member

Joined:
Dec 6, 2006
Messages:
835
5
Trophy Points:
0
Occupation:
Semi-retired EE
Location:
Texan now in Central NY
http://www.daweidesigns.com
Explain how you would go about solving this problem, mentally. We'll go from there.

5. ### isuruesNew Member

Joined:
Aug 25, 2007
Messages:
6
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. ### shabbirAdministratorStaff Member

Joined:
Jul 12, 2004
Messages:
15,376
388
Trophy Points:
83
Do you have any algorithm in mind to go about it?

7. ### isuruesNew Member

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

8. ### shabbirAdministratorStaff Member

Joined:
Jul 12, 2004
Messages:
15,376
388
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. ### isuruesNew Member

Joined:
Aug 25, 2007
Messages:
6
0
Trophy Points:
0
ya thats according to the input n

10. ### isuruesNew Member

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

11. ### madhu_New Member

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

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

Joined:
Sep 22, 2009
Messages:
2