Users Online

· Guests Online: 105

· Members Online: 0

· Total Members: 188
· Newest Member: meenachowdary055

Forum Threads

Newest Threads
No Threads created
Hottest Threads
No Threads created

Latest Articles

C# Program to Sort a String using Predefined Function

C# Program to Sort a String using Predefined Function

 

This is a C# Program to sort a string using predefined function.

Problem Description

This C# Program Sorts a String using Predefined Function.

Problem Solution

Here the string is sorted using the predefined function using sort().

Program/Source Code

Here is source code of the C# Program to Sort a String using Predefined Function. The C# program is successfully compiled and executed with Microsoft Visual Studio. The program output is also shown below.

/*
 * C# Program to Sort a String using Predefined Function
 */
using System;
class linSearch
{
    public static void Main()
    {
        Console.WriteLine("Enter Number of Elements you Want to Hold 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();
    }
}
Program Explanation

 

This C# program, we are reading the number of elements using ‘s’ variable. The string is sorted using the predefined function sort().

 

Using for loop we are entering the coefficient element values of an array. The sort() function is used to sort element values in an ascending order. For loop is used to print the values of the sorted elements of a string.

Runtime Test Cases
 
Enter Number of Elements you Want to Hold in the Array ? 5
Enter Array Elements : 
2
3
1
4
5
Sorted Array :
1
2
3
4
5

 

Comments

No Comments have been Posted.

Post Comment

Please Login to Post a Comment.

Ratings

Rating is available to Members only.

Please login or register to vote.

No Ratings have been Posted.
Render time: 0.94 seconds
10,851,169 unique visits