Ascending And Descending Order In C#

This program explain the Ascending order in C#
  1. using System;  
  2.   
  3. namespace Ascending_Order  
  4. {  
  5.     class Program  
  6.     {  
  7.         static void Main(string[] args)  
  8.         {  
  9.             int i, j;  
  10.             int[] a = new int[20];  
  11.             for (i = 0; i < 5; i++)  
  12.             {  
  13.                 Console.WriteLine("enter the num"+" " + (i + 1)+":");  
  14.                 a[i] = Convert.ToInt16(Console.ReadLine());  
  15.             }  
  16.             for (i = 0; i < 5; i++)  
  17.             {  
  18.                 for (j = 0; j < 4; j++)  
  19.                 {  
  20.                     if (a[j] >a[j + 1])  
  21.   
  22.                     {  
  23.                         int temp = a[j + 1];  
  24.                         a[j + 1] = a[j];  
  25.                         a[j] = temp;  
  26.                     }  
  27.                 }  
  28.             }  
  29.                 Console.WriteLine("Ascending Sort:");  
  30.                 for (i = 0; i <5; i++)  
  31.                 {  
  32.                     Console.WriteLine(a[i] + "");  
  33.                 }  
  34.                     Console.ReadKey();  
  35.                 }  
  36.             }  
  37.         }  
  38.       
This program explain the Descending order in C#
  1. using System;  
  2.   
  3. namespace Descending_Order  
  4. {  
  5.     class Program  
  6.     {  
  7.         static void Main(string[] args)  
  8.         {  
  9.             int i, j;  
  10.             int[] a = new int[20];  
  11.             for (i = 0; i < 5; i++)  
  12.             {  
  13.                 Console.WriteLine("enter the num"+" " + (i + 1)+":");  
  14.                 a[i] = Convert.ToInt16(Console.ReadLine());  
  15.             }  
  16.             for (i = 0; i < 5; i++)  
  17.             {  
  18.                 for (j = 0; j < 4; j++)  
  19.                 {  
  20.                     if (a[j] <a[j + 1])  
  21.   
  22.                     {  
  23.                         int temp = a[j + 1];  
  24.                         a[j + 1] = a[j];  
  25.                         a[j] = temp;  
  26.                     }  
  27.                 }  
  28.             }  
  29.                 Console.WriteLine("Descending Sort:");  
  30.                 for (i = 0; i <5; i++)  
  31.                 {  
  32.                     Console.WriteLine(a[i] + "");  
  33.                 }  
  34.                     Console.ReadKey();  
  35.                 }  
  36.             }  
  37.         }  
  38.