Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- using namespace std;
- int maxSubArraySum(int a[], int size)
- {
- int max_ending =0, max_so_far =0;
- for(int i =0; i<size;i++)
- {
- max_ending = max_ending +a[i];
- if(max_ending <0)
- max_ending = 0;
- if(max_ending>max_so_far)
- max_so_far = max_ending;
- }
- return max_so_far;
- }
- int main()
- {
- int a[] = {-2, -3, 4, -1, -2, 1, 5, -3};
- int n = sizeof(a)/sizeof(a[0]);
- int max_sum = maxSubArraySum(a, n);
- cout << max_sum;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement