C# Program to Sort a String using Predefined Function. - Amit Notes

Latest

Oct 13, 2021

C# Program to Sort a String using Predefined Function.

C# Program to Sort a String using Predefined Function.


The C# program is successfully compiled and executed with VS Code With this you will also get its output below

Code: -

using System;

class amitnotes

{

    public static void Main()

    {

        Console.WriteLine("Enter the number you want to put in the array? ");

        string s = Console.ReadLine();

        int x = Int32.Parse(s);

        int[] a = new int[x];

        Console.WriteLine("Enter Array Elements :");

        for (int i = 0; i < x; i++)

        {

            string s1 = Console.ReadLine();

            a[i] = Int32.Parse(s1);

        }

        Array.Sort(a);

        Console.WriteLine("Sorted Array : ");

        for (int i = 0; i < x; i++)

        {

            Console.WriteLine("{0}",a[i]);

        }

        Console.Read();

    }

}

 

Runtime Test Cases: -

Enter the number you want to put in the array? 5

Enter Array Elements :

2

3

1

4

5

Sorted Array:

1

2

3

4

5

----------------------------------END---------------------------------------

Also Read:-

1.Write a C# Sharp program to find whether a given year is a leap year or not.

2.Write a program in C# Sharp to check whether a number is a palindrome or not.

3.C# Program to Perform Celsius to Fahrenheit Conversion.

4.C# Program to Reverse a String with Predefined Function.

No comments:

Post a Comment

If you have any doubts, Please let me know