Basic Programming C# Examples

C# Program to Sort Elements Of Array in Descending order

The Program in C# Program to Sort Elements Of Array in Descending order is given below:

using System;

namespace ArraySortDescending
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("Hello Codeauri Family, enter the number of elements in the array to sort in descending order: ");
            int n = int.Parse(Console.ReadLine());
            int[] arr = new int[n];

            Console.WriteLine("Enter the elements of the array: ");
            for (int i = 0; i < n; i++)
            {
                arr[i] = int.Parse(Console.ReadLine());
            }

            Array.Sort(arr);
            Array.Reverse(arr);

            Console.WriteLine("Okay, the Sorted array in descending order: ");
            foreach (int item in arr)
            {
                Console.Write(item + " ");
            }
            Console.WriteLine();
        }
    }
}

Output:

Hello Codeauri Family, enter the number of elements in the array to sort in descending order:
3
Enter the elements of the array:
145
4
199
Okay, the Sorted array in descending order:
199 145 4

Pro-Tips💡

Here are the steps by steps execution of above program:

  1. Displays a message asking the user to enter the number of elements in the array to be sorted.
  2. Reads the number of elements in the array from the user.
  3. Creates an array with the specified number of elements.
  4. Displays a message asking the user to enter the elements of the array.
  5. Reads the elements of the array from the user.
  6. Sorts the array in ascending order using the Array.Sort method.
  7. Reverses the order of the elements in the array using the Array.Reverse method.
  8. Displays a message indicating that the array has been sorted in descending order.
  9. Writes the sorted array elements to the console.
  10. Exits the program.

Learn C-Sharp ↗

C-sharp covers every topic to learn about C-Sharp thoroughly.

Learn C Programming ↗

C-Programming covers every topic to learn about C-Sharp thoroughly.

Learn C++ Programming↗

C++ covers every topic to learn about C-Sharp thoroughly.

Codeauri is Code Learning Hub and Community for every Coder to learn Coding by navigating Structurally from Basic Programming to Front-End Development, Back-End Development to Database, and many more.

Related Posts

Programming Languages( Types, Pros and Cons)-Codeauri

What are the types or levels of Programming Languages? The types or levels of programming languages are divided into two types: Types Of Programming Languages: 1.Machine-level Language :1st…

C# Program to Find Sum of Rows & Columns of a Matrix

The Program in C# Program to Find Sum of Rows & Columns of a Matrix is given below: Output: Hello Codeauri Family,enter the number of rows and columns…

C# Program to Calculate Determinant of Given Matrix

The Program in C# Program to Calculate Determinant of Given Matrix is given below: Output: Hello Codeauri Family, enter the number of rows and columns of the matrix…

C# Program to Find Sum of right Diagonals of a Matrix

The Program in C# Program to Find Sum of right Diagonals of a Matrix is given below: Output: Hello Codeauri Family, enter the number of rows and columns…

C# Program to Find Transpose of Given Matrix

The Program in C# Program to Find Transpose of Given Matrix is given below: Output: Hello Codeauri Family, enter the number of rows and columns in the matrix:22Enter…

C# Program for Multiplication of two square Matrices

The Program in C# Program for Multiplication of two square Matrices is given below: Output: Hello Codeauri Family, enter the number of rows/columns in the matrices:2Enter the elements…

Leave a Reply

Your email address will not be published. Required fields are marked *

Your Journey into Code Begins Now: Discover the Wonders of Basic Programming

X