Not covered all cases in given code

if the largest sum is the sum of all elements, then the given code is not correct.

ex::
if array is : 1 2 3 4 5
then according to the given code output is 14 but maximimum sum will be of sum of all elements.(i.e. 15)

The approach and code taught is correct. Please dry run the code again and check.
You can save the code on ide.codingblocks.com and share its link so that i can check.

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.