Counting and printing permutations from 1 to n-1?

let c(n) be the number of different group integers that can be chosen from the integers 1 through n-1, so that the integers in each group add up to n (for example, n=4=[1+1+1+1]=[1+1+2]=[2+2]). Write a recursive definition for c(n) a) where you count permutations. For example, 1,2,1 and 1,1,2 are two groups that each add up to 4

here is what I have. I get 7 as answer but I want a function where I do not have to alter anything in the main:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
int main(){ 
int a=4; 
int sum_perm; 
sum_perm=recurse(a); 
cout<<sum_perm-1<<endl; 
//Can I do -1 here because it should be from a group of integers from 1 to n-1? 
return 0; 
} 

int recurse(int n){ 
int sum = 1; 
if (n == 1){ 
return 1; 
} 
for(int i = 1; i < n; i++){ 
sum += recurse(n - i); 

} 
return sum; 
}
Last edited on
Please do not post more than once:
http://www.cplusplus.com/forum/beginner/158866/
Thanks, for now I have to do things manually. You think you can help?
Topic archived. No new replies allowed.