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 ?
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 ?
Rather aptly, what is "all sum combination of integer"?
Look up a C++ Reference and learn How To Ask Questions The Smart WayOriginally Posted by Bjarne Stroustrup (2000-10-14)
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