Segmentation fault

https://hack.codingblocks.com/app/practice/1/240/problem

please tell me the fault in my recursive solution

@shivamgoel150
There was an issue in your recursion call. You were adding n to variable sum but you were returning solve(n - 1) . This does not include the variable n. Hence the wrong answer. Your function should return n + solve(n - 1). This would give the correct answer.

And dont use freopen while submitting your solutions on CB IDE. It will give a wrong answer. Thus remove the file handling lines.

If my solution is able to answer your query, please mark the doubt as resolved.