Sum of sub array

#include
using namespace std;
//max sub-array sum-cumulative sum
int main() {
// your code goes here

int a[10],n,sum=0,max=0;
int cumSum[10]={0};
cin>>n;
int left=-1,right=-1;

//cumulative sum array
cin>>a[0];
cumSum[0]=a[0];
for (int z = 1; z < n; z++) {
cin >> a[z];
cumSum[z]=cumSum[z-1]+a[z];
}
//generate all sub-arrays
for(int i=0;i<n;i++)
{
    for(int j=i;j<n;j++)
    {
        sum=0;
        sum=cumSum[j]-cumSum[i-1];
        if(sum>max)
        {
            max=sum;
            left=i;
            right=j;
        }
        
        
    }
    
}
cout<<max<<endl<<left<<","<<right;

return 0;

}
Why is my output coming wrong

Hi Shraddha, please share the exact name of the question as well as the link to the problem. Also save your code on ide.codingblocks.com and share the link here.

Hey Shraddha, as you are not responding to this thread, I am marking your doubt as Resolved for now. Re-open it if required. And please mark your doubts as resolved in your course’s “Ask Doubt” section, when your doubt is resolved.