private static void FindSecondSmallest()
{
int[] elements = { 2, 5, 8, -5, -4, 0, 2, 10, 3, -3 };
int smallest = int.MaxValue;
int secondSmallest = int.MaxValue;
for (int i = 0; i < elements.Length; i++)
{
if (elements[i] == smallest)
{
secondSmallest = smallest;
}
else if (elements[i] < smallest)
{
secondSmallest = smallest;
smallest = elements[i];
}
else if (elements[i] < secondSmallest)
{
secondSmallest = elements[i];
}
}
Console.WriteLine(secondSmallest);
}
No comments:
Post a Comment