0
Mentor
Well, as I often say, how would you do it on paper?

Let's say we're finding sums of 15, and we're part way through, and we have 2 at the start of the array.
In the recursive function we want to loop, but from what to what? 1..15? Would there be any point starting at 1 if we just want increasing sums? Would there be any point starting at 2 if we want to avoid duplicates? Once we've decided where we want to start counting from, how would we work that out?

What would be the upper limit? Remember from the output above, the sums starting with 2 are 2+3+4+6, 2+5+8 and 2+6+7.

Having decided on the loop, what now goes in the loop? We want to put the current number in the loop. How do we know what entry in the array to use? The first level would use [0], the second [1], the third [2], is there a pattern here that we could work out from something?

After assigning something to somewhere in the array, what next? Let's say we've got 2+3. Does this add up to 15? Do we want to print anything? Do we want to recurse deeper? What about when we get to 2+13 (just realised that's missing from my output above - bug fixed). Same three questions. Would it be appropriate to use an if/else here? What would the test be? What would we do (a) if that test is true; (b) if that test is false?

Corrected output for 15:

Enter a number: 15
1+2+3+4+5
1+2+3+9
1+2+4+8
1+2+5+7
1+2+12
1+3+4+7
1+3+5+6
1+3+11
1+4+10
1+5+9
1+6+8
1+14
2+3+4+6
2+3+10
2+4+9
2+5+8
2+6+7
2+13
3+4+8
3+5+7
3+12
4+5+6
4+11
5+10
6+9
7+8
0
Mentor
Correction: the sums starting with 2 are:
2+3+4+6
2+3+10
2+4+9
2+5+8
2+6+7
2+13
0
Contributor
But xpi0t0s, the sum beginning with 1 can also be with repeatations, I mean;
1+1+1+1+1+1+1+1+1+1+1+1+1+1+1=15
isn't it??
0
Mentor
There aren't any repeats in the opening post. Two examples were given, neither show any repeats. The second was:

> example 2.. if the user entered 6.. the output should be:
> 1+2+3
> 1+5
> 2+4
> 6

As you see, 1+1+1+1+1+1 wasn't listed, nor were 1+1+4, 2+2+2, 3+3 and so on.

This is why you shouldn't hijack other people's threads. If you've got *EXACTLY* the same issue then maybe it's OK but it's still better to open your own thread so that any help is specific to your situation. There's no shortage of numbers and it doesn't cost anything to create a new thread. And if you've got a different issue then it'll only create confusion, as you can see.
0
Contributor
Sorry....the moment I saw the thread, I went for trying it, without reading it completely....I have no intention to hijack someone's thread, not even of opening a new thread...I am extremely sorry....
0
Mentor
Of course, if duplicates are allowed, then the sums of 15 starting with 2 are too many to list here; I count 4096. The first few:
2+1+1+1+1+1+1+1+1+1+1+1+1+1
2+1+1+1+1+1+1+1+1+1+1+1+2
2+1+1+1+1+1+1+1+1+1+1+2+1
2+1+1+1+1+1+1+1+1+1+1+3
2+1+1+1+1+1+1+1+1+1+2+1+1
2+1+1+1+1+1+1+1+1+1+2+2
2+1+1+1+1+1+1+1+1+1+3+1
2+1+1+1+1+1+1+1+1+1+4

some more:
2+1+3+2+4+1+1+1
2+1+3+2+4+1+2
2+1+3+2+4+2+1
2+1+3+2+4+3
2+1+3+2+5+1+1
2+1+3+2+5+2
2+1+3+2+6+1
2+1+3+2+7
2+1+3+3+1+1+1+1+1+1

and the last few:
2+9+4
2+10+1+1+1
2+10+1+2
2+10+2+1
2+10+3
2+11+1+1
2+11+2
2+12+1
2+13
0
Mentor
In total I got 16384 sums adding up to 15, just using positive non-zero integers.
0
Contributor
I have counted them as well...that's what was confusing me...