Элементы между min & max - C#
Формулировка задачи:
В массиве найти минимальный и максимальный элемент. В промежутке между ними элементы записать в обратном порядке (включая min & max)
Решение задачи: «Элементы между min & max»
textual
Листинг программы
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace test1
{
class Program
{
static void Main(string[] args)
{
int[] mas = { 46, 23, 21, 53, 321, 5, 2, 3, 62 };
int max = mas[0];
int min = mas[0];
int position = 0;
int from = 0;
int to = 0;
foreach (int elem in mas)
{
if (max < elem)
{
max = elem;
from = position;
}
if (min > elem)
{
min = elem;
to = position;
}
position++;
}
if(from < to)
{
position = from;
from = to;
to = position;
}
for (int i = from; i >= to; --i)
Console.Write(" " + mas[i]);
Console.ReadKey();
}
}
}