# sum combination

This is a discussion on sum combination within the C Programming forums, part of the General Programming Boards category; need to print all sum combination of integer; Code: void what(int sum) { int i; for(i=1; i<=sum; i++) { printf("%d",i); ...

1. ## sum combination

need to print all sum combination of integer;

Code:
```void what(int sum)
{
int i;
for(i=1; i<=sum; i++)
{
printf("%d",i);
what(sum-i);
}
puts("");
}

void main()
{

what(4);

}```

what i should change ?

2. Rather aptly, what is "all sum combination of integer"?

3. Originally Posted by laserlight
Rather aptly, what is "all sum combination of integer"?

what(4)

1111
211
22
31
4

4. You could try some thing of this sort

4 can be written this way

1111
Now you increment the first digit and decrement the last digit. Rest remain the same
2110

Do the same thing again
2200

Do the same thing again
3100

0 cannot be decremented so we cannot increment 1. Therefore the next one will be
4000

5. Originally Posted by abhimanipal
you could try some thing of this sort

4 can be written this way

1111
now you increment the first digit and decrement the last digit. Rest remain the same
2110

do the same thing again
2200

do the same thing again
3100

0 cannot be decremented so we cannot increment 1. Therefore the next one will be
4000

so ?

6. Originally Posted by the_contractor
so ?
That is an answer and not a bad one at that. He/she was trying not to do your work for you so they showed you logic that could lead you to all possible results.