Reccursion

I know how to get the 155, but how is rec(19683) printing 16633? I'm getting 19633 for some reason. Thanks for taking the time to read.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#include <iostream>
using namespace std;

int rec (int n) {
    if (n < 10) return n;
    return 100 * rec(n / 100) + 11 * (n % 10);
}

int main () {

    cout << rec(135) << endl; // prints 155
    cout << rec(19683) << endl; // prints 16633, but how?

return 0;
}
What does it mean that you are getting 19633? Did you do the calculation by hand? Then most probably you made a mistake... Computers might not have imagination, but they are pretty good with maths!
Yeah I 'm doing it by hand, I want to know why I'm getting a different answer.
As I said, check your calculation: there must be some mistake.
Topic archived. No new replies allowed.