Posts Tagged ‘sorting’

Sorting Program using C#

namespace SortingNos
{
   class Program
   {
       static void Main(string[] args)
       {
           Console.WriteLine("Enter Numbers :");
           int[] arr = new int[5];
           string arr1 = "";
           for (int i = 0; i < 5; i++)
 {
 arr1 = Console.ReadLine();
 arr[i] = Convert.ToInt32(arr1);            
}
 
 int a, b, temp = 0;
 Console.WriteLine();
 for (a = 0; a < arr.Length; a++)
           {
                               for(b=a+1;b< arr.Length;b++)
               {
                   if (arr[a] > arr[b])
                   {
                       temp = arr[a];
                       arr[a] = arr[b];
                       arr[b] = temp;
                   }
               }             
               Console.WriteLine(arr[a]);              
           }          
          Console.ReadLine();
       }
   }
}

Download

Popularity: 4% [?]

Designed by: Business Web Hosting | Thanks to Buy Icons, travel tips and Used Cars