Answer the question
In order to leave comments, you need to log in
Why if the last element is minimal, then another element becomes minimal?
This function counts the sum of array elements after the minimum, if the minimum is the last element of the array, then this function for some reason takes the previous minimum and calculate the sum after it, and if the function has two identical minimums, then it displays the sum after the first. Please help fix these two
{
{
int min = array[0], res = 0, count = 0;
for (int i = 0; i < array.Length - 1; i++)
{
if (array[i] < min)
{
min = array[i];
count = i;
}
}
for (int j = count + 1; j < array.Length; j++)
{
res += array[j];
}
return res;
}
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question