Saturday 3 December 2016

C# ARRAY PROGRAM

using System;
usingSystem.Collections.Generic;
usingSystem.Linq;
usingSystem.Text;

namespace ConsoleApplication2
{
classProgram
    {
staticvoid Main(string[] args)
        {
int[] a = { 1, 9, 3, 4, 0 };
Sort(a);
int[] b = { 1, 9, 3, 4, 0 };

Console.WriteLine();

Array.Sort(b);
foreach (int x in b)
Console.Write(x);

Console.WriteLine();

Array.Reverse(b);
foreach (int x in b)
Console.Write(x);

Console.ReadLine();
        }
staticvoid Sort(int[] a)
        {
for (int i = 0; i <a.Length; i++)
            {
for (int j = 0; j <a.Length - 1; j++)
                {
if (a[j] > a[j + 1])
                    {
int temp = a[j];
a[j] = a[j + 1];
a[j + 1] = temp;
                    }
                }
            }
foreach (int x in a)
Console.Write(x);
        }
    }
}


OUTPUT
        01349

        01349

        94310

No comments:

Post a Comment