How to Sort Numbers in an Array in C#

This is the simple and logic building program related to array. The program will sort all the numbers in a given array in ascending order.

Source Code 

using System;
using System.Collections.Generic;
using System.Text;

namespace assad
{
class sortArrays
{
static void Main(string[] args)
{
welcomeScrean();
int[] array = new int[10];
Random rnd = new Random();
Console.WriteLine("Random Numbers");
for ( int i = 0 ; i < array.Length ; i++ ) {
array[i] = rnd.Next(0, 101); // generates a random array
Console.WriteLine(array[i]);
}
Array.Sort(array); // sorts array
Console.WriteLine("Sorted Numbers");
for ( int i = 0 ; i < array.Length ; i++ ) {
Console.WriteLine(array[i]);
}
int ab = Console.Read();
}
private static void welcomeScrean()
{
Console.ForegroundColor = ConsoleColor.Green;
Console.Write("\t*******************************************************" + "\n"
+ "\t*******************************************************" + "\n"
+ "\t** Sort **" + "\n"
+ "\t** Numbers Array **" + "\n"
+ "\t** Program **" + "\n"
+ "\t*******************************************************" + "\n"
+ "\t*******************************************************\n\n\n\n");
}
}
}

Output of the Program

 
Sort Numbers in an Array in C#

Share on Google Plus

About Asad

Asad Niazi is Software Engineer , Programmer, Web Developer and a young mentor of BloggersTown and PProgramming. Asad Love to writes about Technology, Programming, Blogging and make money online.
    Blogger Comment
    Facebook Comment

0 comments:

Post a Comment