Answer the question
In order to leave comments, you need to log in
How to find the minimum element in the first 5 elements of a one-dimensional array?
Hello.
There is some one-dimensional array with type data float
and consisting of 20 elements.
float[] firstArray = { 4, 2, 0, 1, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20 };
float[] firstArray = { 4, 2, 0, 1, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20 };
float[] secondArray = new float[5];
for (int i = 0; i < 5; i++)
secondArray[i] = firstArray[i];
float min = secondArray.Min();
Answer the question
In order to leave comments, you need to log in
firstArray.Take(5).Min()
if you want LINQ
in the general case like this
float[] firstArray = { 4, 2, 0, 1, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20 };
int index = 0
for (int i = 0; i < 5; i++)
{
if (firstArray[i] < firstArray[index])
{
index = i
}
}
min = firstArray[index]
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question