Write a program to sort 20 decimal numbers in decreasing order and print the
result.
i have solution but lengthy.
decimal[] arr = { 12.3m, 45.2m, 5.4m, 23.44m, 43.21m, 31.34m, 4.3m, 21.3m,
34.2m, 32.1m, 44.2m, 6.4m, 64.3m, 3.4m, 5.32m, 32.345m, 4.34m, 23.4m,
45.234m, 5.31m };
for (int i = 0; i < arr.Length; i++)
{
Console.WriteLine(arr[i]);
}
Console.WriteLine("\n--Number in decreasing order--\n");
int count = 0;
while (count < arr.Length - 1)
{
if (arr[count] < arr[count + 1])
{
decimal temp = arr[count];
arr[count] = arr[count + 1];
arr[count + 1] = temp;
count = 0;
continue;
}
count++;
}