// Sort.cs -- Sorts and array in ascending order, then reverses the elements
using System;
public class Sort
{
static public void Main ()
{
DateTime now = DateTime.Now;
Random rand = new Random ((int) now.Millisecond);
int [] Arr = new int [12];
for (int x = 0; x < Arr.Length; ++x)
{
Arr [x] = rand.Next () % 101;
}
Console.WriteLine ("The unsorted array elements:");
foreach (int x in Arr)
{
Console.Write (x + " ");
}
Array.Sort (Arr);
Console.WriteLine ("\r\n\r\nThe array sorted in ascending order:");
foreach (int x in Arr)
{
Console.Write (x + " ");
}
Array.Reverse (Arr);
Console.WriteLine ("\r\n\r\nThe array sorted in descending order:");
foreach (int x in Arr)
{
Console.Write (x + " ");
}
}
}
|