#include #include // max_subarray_sum should return the largest contiguous sum // of a subarray in a given array // eg // For an array with elements 8, 3, 5, 4, -1, 3, -5, -4 // you would get 22 from elements 8 + 3 + 5 + 4 + -1 + 3 int max_subarray_sum(int size, int array[]) { int max_sum = array[0]; int start = 0; while (start < size) { int stop = start; while (stop < size) { // start and stop are now set correctly // calculate the sum int sum = 0; int i = start; while (i <= stop) { sum += array[i]; i++; } // is this the biggest sum?? if (sum > max_sum) { max_sum = sum; } stop++; } start++; } return max_sum; } // This is a simple main function which could be used // to test your sum_cont_subarray function. // It will not be marked. // Only your sum_cont_subarray function will be marked. int main(void) { int test_array[] = {8, 3, 5, 4, -3, 3, -5, -4}; int max_sum = max_subarray_sum(8, test_array); printf("%d\n", max_sum); return 0; }