I am trying write a recursive function(it must be recursive) to print out the partitions and number of partitions for 1 to n-1.
For example, 4 combinations that sum to 4:
1 1 1 1
1 1 2
1 3
2 2
I am just having much trouble with the function. This function below doesn't work. Can someone help me please?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
int partition(int n, int max)
{
if(n==1||max==1)
return(1);
int counter = 0;
if(n<=max)
counter=1;
for(int i = 0; n>i; i++){
n=n-1;
cout << n << "+"<< i <<"\n";
counter++;
partition(n,i);
}
return(counter);
}