在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
//输入一组整数。求出这组数字子序列和中最大值 #include <stdio.h> 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; } |
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论