C++,Recursion,Three Number combination if their sum less than 10.

4    03 Aug 2016 22:36 by u/Jeena6

Print the number in this format using recursion like {0,1,2} {0,1,3} {0,1,4} {0,2,3} {0,2,4} {0,3,4} {1,2,3} {1,2,4} {1,3,4} {2,3,4}

9 comments

2

Haven't done c++ in a while, so this could be, ya know, not the correct syntax, but you'll figure it out.

public void lt_ten(int i, int j, int k){
    if((i + j + k + 1) < 10)
    {
        lt_ten(i + 1, j, k);
        lt_ten(i, j+1, k);
        lt_ten(i, j, k +1);
    }
    cout << '{' + i + ',' + j + ',' + k + '}\n';
}
2

You might have it confused with a different language. "public" is used only on classes, this is a function type.
void main() should be sufficient.
Your cout syntax should be

cout<< "{" <<i<<","<<j<<","<<k<<"}"<<endl;

1

Yes I must, too much damn java at work.

0

cout<< "{" <<i<<","<<j<<","<<k<<"}"<<endl;

Why do people even like C++. "cout left shifted by open brace"?

0

Those are only left shifts if you use them as logical operators. But in this case it is for namespace

1

In the case of complicated command-line printing, I still prefer to use C's printf. It's less confusing and more readable, in my opinion.

printf('{%d,%d,%d}\n',i,j,k);
2

Is there a rule in this sub against doing peoples' homework for them?

1

I can't see one. Sometimes lower level problems help mix it up in contrast to the technically in depth articles which apply to ~15% of programmers and 10% of programmers understand (looking at you RUST). A lower level problem, or particularly a fun mid level problem can help bring more programmers together.

Though yes, it is annoying seeing other people's homework, they don't benefit from having others do their homework, and sometimes I enjoy seeing unique problems, I hate see the giant problem lists that float around. In the mean time, their incompetence (from not doing their homework) makes the rest of us look better on the market, so it's not helping them, and it's not hurting us.

1

Nice sum-up of the issues, I see it pretty much the same way. On the one hand, giving someone a pre-made answer on a plate does them a disservice in terms of the value they get from their education, and it can be like feeding seagulls, where suddenly you're getting spammed with every first-year assignment question around.

On the other hand, sometimes they're fun little exercises to do just to inject some variety into your day.