/*************************************************************************
> File Name: 29_GreatestSumOfSubArray.c
> Author: Juntaran
> Mail: JuntaranMail@gmail.com
> Created Time: 2016年09月01日 星期四 20时37分22秒
************************************************************************/ #include <stdio.h> int FindGreatestSumOfSubArray(int* nums, int length)
{
if (nums==NULL || length<=)
{
printf("error\n");
return -;
} int CurSum = ;
int MaxSum = ; for (int i = ; i < length; ++i)
{
if (CurSum <= )
CurSum = nums[i];
else
CurSum += nums[i]; if (CurSum > MaxSum)
MaxSum = CurSum;
}
printf("MaxSum is %d\n", MaxSum);
return MaxSum;
} int main()
{
int nums[] = {,-,,,-,,,-};
int length = ;
FindGreatestSumOfSubArray(nums, length);
}