In my hw problem there is this code
#include <iostream>
using namespace std;
int fun(int x) {
if (x <= 0) return 0;
if (x >= 9 && x % 2 == 1) return x - 1;
if (x >= 9 || x % 3 == 0) return x - 2;
return 7;
}
int rec(int x) {
if (x < 10) return fun(x);
return rec(x / 10) + rec(x % 10);
}
int main() {
cout << fun(3) << endl; // line (a)
cout << fun(30) << endl; // line (b)
cout << fun(33) << endl; // line (c)
cout << rec(33) << endl; // line (d)
cout << rec(999) << endl; // line (e)
}
What is rec(999), I found out the answer is 24, but can someone help me understand why its 24? Thanks