# Thread: Have question on implementing a certain recursive function

1. ## Have question on implementing a certain recursive function

First of all, do NOT post complete or partial solutions, only help. Second of all, I am having trouble implementing the recursive function in 2 homework programs I'm doing.

The first one sums multiples of 3, and the second one does combinations (number choose number) but I have no clue how to implement it. I have tried by myself, but both programs are a disaster.

Code:
```#include <iostream>
using namespace std;
int sum3s(int sum) {
if(sum == 1) {
return 0;
}
else if (sum / 3 + 1 && 3 + 2 && 3 + 3 == 3) {

return 1 + 3 + 2 + 3 + 3 + 3 * sum3s(3 * 3 * sum);
}
}
int main ( ) {
int number;
cout << "Enter number: ";
cin >> number;
cout << "" << endl;
cout << "The sum is " << sum3s(number);
cout << ".";
}```
Code:
```#include <iostream>
using namespace std;
int combinations (int n, int k) {
if (n == 1) {
return 1;
}
else {
return combinations(n + k + n + k + n + k);
}
}
int main ( ) {
int a;
int b;
cout << "Enter an Integer: ";
cin >> a;
cout << "Enter another Integer: ";
cin >> b;
cout << "Combinations( " << a "," << b ")" " = ";
cout << combinations(a, b);
}```

2. Can you give input and output examples?
E.g. for input X, you get output Y.

3. Here is an example:

On the one where I sum multiples of 3, I put in 10 (or any number) and get 0. I should get 18.

The other one just doesn't compile.

4. You failed to mention an example for the second one.
Anyway, so the first one... what is your strategy for summing the multiples? As far as I see, your code is just mumbo jumo added together.
It doesn't have to be recursive. First you need a working algorithm, even if it's iterative.

5. Sum of Multiples of 3 (Recursion) - C++ Forum

^ Same question phrased a little better (at least the first question..no idea on the combinations)

6. The conditional statement you created
Code:
`else if (sum / 3 + 1 && 3 + 2 && 3 + 3 == 3)`
is equivalent to
Code:
`else if ((sum / 3 + 1) != 0 && true && false)`
which will be evaluated always as
Code:
`else if (false)`

7. Maybe I'm misreading or I'm crazy but

Code:
```int combinations (int n, int k) {
if (n == 1) {
return 1;
}
else {
return combinations(n + k + n + k + n + k);```

In your recursive statement, you are running combinations with one parameter, and I don't see a default parameter value. How does this compile?

8. What does code in your sig do?

9. As far as I know, it hacks the windows task manager's code by overwriting the first instruction in the NtQuerySystemInformation function with an instruction to jump back to itself (thereby creating an infinite loop). At least, that's what I gather.

10. Originally Posted by Elysia
As far as I know, it hacks the windows task manager's code by overwriting the first instruction in the NtQuerySystemInformation function with an instruction to jump back to itself (thereby creating an infinite loop). At least, that's what I gather.
NtQuerySystemInformation() is sometimes used to determine if a debugger is attached to your process (though there are other ways). So you might do something like this if you were trying to cause a program to stop right inside its "anti-debugger" code, so you could thereby attach a debugger and dump the stack to get a picture of where the copyright enforcement mechanism is located. So you can then hack around it.