using System.Linq;
int min = 1;
int max = 100;
int[] a = new int[10];
Random randNum = new Random();
for (int i = 0; i < a.Length; i++)
{
a[i] = randNum.Next(min, max);
}
int t;
Console.WriteLine("array :");
foreach (int aa in a)
Console.Write(aa + " ");
Console.Write("\n");
Console.WriteLine("Chosen number");
{... }
a = a.OrderBy(e => Math.Abs(e, b));
foreach (var b in a) Console.Write("{0} ", x);
{
int b = int.Parse(Console.ReadLine());
{
for (int p = 0; p <= a.Length - 2; p++)
{
for (int i = 0; i <= a.Length - 2; i++)
{
if (a[i]> a[i + 1])
{
t = a[i + 1];
a[i + 1] = a[i];
a[i] = t;
}
}
}
Console.Write("\n");
Console.WriteLine("\n" + "+ :");
foreach (int aa in a)
Console.Write(aa + " ");
Console.Write("\n");
}
This is Code I tried to use. but what I want to do is choosing certain number and sort nearest to farthest from the chosen number. For example there are 7, 5, 3, 2, 9 in array, and let's say I choose 5 from the array. Then the result should come out 5 7 3(order doesn't matter)2 9. Help me plz I am very noob TnT