This is Discussion thread about Maximum Subarray Sum
Discussion About Maximum Subarray Sum
why is this giving 0 as the answer?
#include
using namespace std;
int main() {
int n;
cin>>n;
int a[1000];
for (int r=0;r<n;r++){
cin>>a[r];
}
int msum=0;
int csum;
for (int i=0;i<n;i++){
for(int j=i;j<n;j++){
csum=0;
for (int k=i;k<=j;k++){
csum=csum+a[k];
}
if (csum>msum){
csum=msum;
}
}
}
cout<<msum;
return 0;
}