Skip to content

Commit

Permalink
Modify Maximum consecutive sum in C++
Browse files Browse the repository at this point in the history
  • Loading branch information
BroLeaf committed Oct 7, 2019
1 parent f76788b commit 00ef3a3
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions dynamic_programing/C++/Maximum_Consecutive_Sum.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@ using namespace std;

int main()
{
int array[7] = {7, 6, -5, -8, 6, -2, 10}; // Maximum consecutive sum would be 6 + (-2) + 10 = 14
int sum = 0;
int max_sum = array[0];
for (int i = 0; i < length; ++i)
for (int i = 0; i < (sizeof(array)/sizeof(int)); ++i)
{
sum += array[i];
sum = max(0, sum);
max_sum = max(sum, max_sum);
}
return max_sum;
cout << max_sum;
return 0;
}

0 comments on commit 00ef3a3

Please sign in to comment.