Input: arr[] = {2, 3, -8, 7, -1, 2, 3}
Output: 11
Explanation: The subarray {7, -1, 2, 3} has the largest sum 11.Input: arr[] = {-2, -4}
Output: –2
Explanation: The subarray {-2} has the largest sum -2.Input: arr[] = {5, 4, 1, 7, 8}
Output: 25
Explanation: The subarray {5, 4, 1, 7, 8} has the largest sum 25.
// C# Program to find the maximum subarray sum using nested loops
using System;
class GfG {
// Function to find the sum of subarray with maximum sum
static int MaxSubarraySum(int[] arr) {
int res = arr[0];
// Outer loop for starting point of subarray
for (int i = 0; i < arr.Length; i++) {
int currSum = 0;
// Inner loop for ending point of subarray
for (int j = i; j < arr.Length; j++) {
currSum = currSum + arr[j];
// Update res if currSum is greater than res
res = Math.Max(res, currSum);
}
}
return res;
}
static void Main() {
int[] arr = {2, 3, -8, 7, -1, 2, 3};
Console.WriteLine(MaxSubarraySum(arr));
}
}

I genuinely enjoy reading through on this internet site, it holds superb posts.
Thanks for sharing. I read many of your blog posts, cool, your blog is very good. https://accounts.binance.bh/register/person?ref=QCGZMHR6
Your article helped me a lot, is there any more related content? Thanks!
Can you be more specific about the content of your article? After reading it, I still have some doubts. Hope you can help me.
Thanks for sharing. I read many of your blog posts, cool, your blog is very good.
[279611]supplies professional anti-violence equipments and solutions for the whole world with strong and perfect production capacity. anti-violence.org
Your article helped me a lot, is there any more related content? Thanks!
Your article helped me a lot, is there any more related content? Thanks!
Can you be more specific about the content of your article? After reading it, I still have some doubts. Hope you can help me.