Quantcast

C++ genniouses rescue me!

Yeti

Monkey
May 17, 2005
877
0
yeti cave@the beach
allright...i gotta write a c++ programm that uses recursion to show all the partitions of a natural number. for example with 4:
1+1+1+1,2+1+1,1+2+1,1+1+2,2+2,1+3,3+1,4
my idea is:nopity: :
void Partition(int n, int partition[], int amount)
{
int i;
if (n==0){
cout<<partition[0];
for (int i=1;i<amount;i++)
cout<<"+"<<partition;
}
else
{
for (int i=1;i<n;i++)
{
partition=amount;
Partition(n-1,partition,amount+1);

}
}
}


this is just the function...which in theory should work, when i try to compile it....it doesn't work (i wouldn't be posting this if it did:rant: ).
can some genious out there tell me if my function is wrong?...or maybe post the complete code that can be compiled. i've got one but it returns pure crap and some signs that it might work. cheers! and thanks!:cheers:
 

binary visions

The voice of reason
Jun 13, 2002
22,162
1,261
NC
Between your writing skills and request to just post the complete code for compilation, I'd say you'd better work this out yourself and stay in school.
 

$tinkle

Expert on blowing
Feb 12, 2003
14,591
6
also, your sentinel logic is flawed. you will never see output.

your future employer begs you to struggle through this.