Skip to content

Commit

Permalink
Added Kadane's in C #85 (#279)
Browse files Browse the repository at this point in the history
  • Loading branch information
robertpoziumschi authored and thuva4 committed Sep 29, 2018
1 parent 6c8b31e commit 6de7996
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
Binary file added Kadane's/C/a.out
Binary file not shown.
18 changes: 18 additions & 0 deletions Kadane's/C/kadanes.c
@@ -0,0 +1,18 @@
#include <stdio.h>
#include <limits.h>

int main() {
int v[] = {-2, -3, 4, -1, -2, 1, 5, -3};
int currentMax = 0, globalMax = INT_MIN;
int size = sizeof(v) / sizeof(v[0]);
for (int i = 0; i < size; i ++) {
currentMax += v[i];
globalMax = globalMax < currentMax ? currentMax : globalMax;

if (currentMax < 0) {
currentMax = 0;
}
}
printf("Max sum is %d\n", globalMax);
return 0;
}

0 comments on commit 6de7996

Please sign in to comment.