Docstoc

code of Ascending or Descending in c#

Document Sample
code of Ascending or Descending in c# Powered By Docstoc
					Acending or Decending;
class Program
 {
   public void accen()
   {
     int[] x = new int[5];
     int i,j, t;
     Console.Write("enter array of 5 numbers= \n");
     for (j = 0; j <= 4; j++)
     {
        for (i = 0; i < 3; i++)
        {
            x[i] = Convert.ToInt16(Console.ReadLine());
            if (x[j] > x[i + 1])
            {
                t = x[j];
                x[j] = x[i + 1];
                x[i + 1] = t;

           }

         }
       }
       Console.WriteLine("accending order is = \n \n");
       for (i = 0; i <= 4; i++)
       {

         Console.Write(x[i]);


       }
       Console.ReadLine();
   }

   public void decend()
   {
     int[] x = new int[5];
     int i,j, t;
     Console.Write("enter array of 5 numbers= \n");
     for (j = 0; j <= 4; j++)
     {

         for (i = 0; i <= 4; i++)
         {
           x[i] = Convert.ToInt16(Console.ReadLine());
           if (x[j] < x[i + 1])
           {
               t = x[j];
               x[j] = x[i + 1];
               x[i + 1] = t;

           }
        }
      }
      Console.WriteLine("decending order is = \n \n");
      for (i = 0; i <= 4; i++)
      {

         Console.Write(x[i]);


      } Console.ReadLine();

    }
    static void Main(string[] args)
    {
      int w;
      do
      {
         int z;
         Program p = new Program();
         Console.WriteLine("\n \n 1 - Accending order");
         Console.WriteLine("\n \n 2 - Decending order");
         Console.WriteLine("\n \n 3 - Exit");
         z = Convert.ToInt16(Console.ReadLine());
         if (z == 1)
         {
             p.accen();
         }
         else if (z == 2)
         {
            p.decend();

         }

         else if (z == 3)
         {
           break;
         }
         else
         {
           Console.WriteLine("invalid entery");
         }
   Console.WriteLine("do u want to continue press 1 for yes and press 2 for no =
");
         w = Convert.ToInt16(Console.ReadLine());
      }
      while (w == 1);

				
DOCUMENT INFO
Shared By:
Categories:
Stats:
views:104
posted:5/27/2010
language:English
pages:2