Getting segmentation error
You have to solve this question using dynamic programming approach since it is an example of overlapping subproblems
ur recursion is running infinitely
u r not checking if n is negative like
if n=6
n-1=5
but n-4=2
now there is no case to handle n=2 hence when again recusion will call n became negative and recursion is going on infinitely