Answers for "sum of largest 4 number from an array c#"

C#
9

find largest number in array c#

int biggest = list[0];//list refer to your list's name
for(int i = 1;i < list.Count;++i)
{
	if(list[i] > biggest)
    {
     	biggest = list[i]; 
    }
}
//now biggest will be the biggest number of the list
Posted by: Guest on March-05-2021
3

maximum sum subarray c#

public static int SumArray()
{
    var arr = new int[]{ -2, -4, -5, -6, -7, -89, -56 };
    var sum = 0;
    var max = arr[0];
    foreach (var item in arr)
    {
        sum += item;
      // sum = Math.Max(sum,0); resting here will not give  expected output
        max = Math.Max(sum,max);
        sum = Math.Max(sum,0);
    }
    return max;
}
Posted by: Guest on March-01-2022

Code answers related to "sum of largest 4 number from an array c#"

C# Answers by Framework

Browse Popular Code Answers by Language