for(i= 0 ; i<n ; i++){
for(j=i; j<n; j++)
{
sum= cumsum[ j ]-cumsum[ i-1 ];
}
}
If for first iteration i=0
then i-1=-1
so for cumsum[ i-1 ] with i=0 should give error???
for(i= 0 ; i<n ; i++){
for(j=i; j<n; j++)
{
sum= cumsum[ j ]-cumsum[ i-1 ];
}
}
If for first iteration i=0
then i-1=-1
so for cumsum[ i-1 ] with i=0 should give error???
prateek sir has written this code and it is working
@abhayg1602 yes it may or may not give garbage in our compiler but in online coding comp it will always give run time error so you have to make sure i-1>=0
I have tested it on many ide its working but ideally it should not??
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.