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 :
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 ).
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!
1+1+1+1,2+1+1,1+2+1,1+1+2,2+2,1+3,3+1,4
my idea is :
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 ).
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!