#include <iostream>
#include<climits>
using namespace std;
int main() {
int n=5;
int arr[5]={1,2,3,4,5};
int maxSum=INT_MIN;
for(int st=0;st<n;st++){
int currSum=0;
for(int end=st;end<n;end++){
currSum+=arr[end];
maxSum=max(currSum,maxSum);
}
}
cout << "max subarray sum = " << maxSum<<endl;
return 0;
}
To embed this program on your website, copy the following code and paste it into your website's HTML: