【C语言】输入一组整数,求出这组数字子序列和中最大值

//输入一组整数,求出这组数字子序列和中最大值
#include 
int MAxSum(int arr[],int len)
{
	int maxsum = 0;
	int i;
	int j;
	for (i = 0; i < len; i++)
	{
		int thissum = 0;
		for (j = i; j < len; j++)
		{
			thissum += arr[j];
			if (thissum>maxsum)
				maxsum = thissum;
		}
	}
	return maxsum;
}
int main()
{
	int arr1[] = { -2, 11, -4, 13, -5, -2 };                     
	int arr2[] = { -6, 2, 4, -7, 5, 3, 2, -1, 6, -9, 10, -2 };   
	printf("arr1最大子序列和为:%d\n", MAxSum(arr1, sizeof(arr1) / sizeof(arr1[0])));  //20
	printf("arr2最大子序列和为:%d\n", MAxSum(arr2, sizeof(arr2) / sizeof(arr2[0])));  //16
	return 0;
}

你可能感兴趣的:(【C语言】输入一组整数,求出这组数字子序列和中最大值)