Сортировка массивов - C# (179257)
Формулировка задачи:
Задать одномерный массив. Найти в нем минимальный элемент. Вычесть из каждого элемента данный минимальный элемент и отсортировать данный массив по возрастанию.
Решение задачи: «Сортировка массивов»
textual
Листинг программы
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
using System.Runtime.InteropServices;
namespace TestSharp
{
class Program
{
static void Main(string[] args)
{
int n = 5;
int min;
int[] array = new int[5] {4,5,1,2,9 };
Console.WriteLine("Current array:");
showArray(array);
Array.Sort(array);
min = array[0];
for(int i = 0; i < array.Length; i++)
{
array[i] -= min;
}
Array.Sort(array);
Console.WriteLine("\nSorted array after all operations: ");
showArray(array);
}
protected static void showArray(int[] arr)
{
for (int i = 0; i < arr.Length; i++)
{
Console.Write(arr[i] + " ");
}
Console.WriteLine();
}
}
}