Wednesday, 2 September 2015

find duplicate value in array using C#

//find duplicate value in array using C#

static void Main(string[] args)
        {

            Console.WriteLine("Please enter limit of arry");
            int i = Convert.ToInt32(Console.ReadLine());
            int[] arry = new int[i];
            for (int j = 0; j < arry.Length; j++)
            {
                Console.Write("\nEnter your number:\t");
                arry[j] = Convert.ToInt32(Console.ReadLine());

            }
            ArrayList list = new ArrayList();
            Console.WriteLine("\n\n");
       
            for (int k = 0; k < arry.Length; k++)
            {
                for (int l = k; l < arry.Length - 1; l++)
                {
                    if (arry[k] == arry[l + 1])
                    {
                        list.Add(arry[k]);
                    }
                }
            }

            if (list.Count == 0)
            {
                Console.WriteLine("No dulicate value");
            }
            else
            {
                foreach (var _list in list)
                {
                    Console.WriteLine("No of value {0}", _list);
                }
            }

         
            Console.ReadKey();
        }

No comments:

Post a Comment