Considering this is certainly an academic exercise, it may behoove you to understand how the recursion is working.
We can modify your code to print out a call tree, showing each invocation:
#include <stdio.h>
void get(int n, int depth)
{
static int call = 1;
printf("%3d: %*sget(%d)\n", call++, 2*depth, "", n);
if (n<1)
return;
get(n-1, depth+1);
get(n-3, depth+1);
}
int main(void)
{
get(6, 0);
return 0;
}
Output:
1: get(6)
2: get(5)
3: get(4)
4: get(3)
5: get(2)
6: get(1)
7: get(0)
8: get(-2)
9: get(-1)
10: get(0)
11: get(1)
12: get(0)
13: get(-2)
14: get(2)
15: get(1)
16: get(0)
17: get(-2)
18: get(-1)
19: get(3)
20: get(2)
21: get(1)
22: get(0)
23: get(-2)
24: get(-1)
25: get(0)
Note that I am assuming your assignment states if (n<1)
("one"), not if (n<l)
("ell"). Also, notice that I added a depth
parameter. This allowed me to indent each call appropriately.