Write a program in C# Sharp to count a total number of duplicate elements in an array.


         class Program
            {
                static void Main(string[] args)
                {
                    int[] num = new int[] { 0112344565,
                             90771020010000 };
                    System.Console.WriteLine($"There is  
                    {CheckDuplicate(num)} duplicates number");
                
                }

                // Write a program in C# Sharp to count a total 
                //number of duplicate elements in an array.
                public static int CheckDuplicate(int[] numbers)
                {

                    int total = 0;

                    for (int i = 0i < numbers.Lengthi++)
                    {

                        for (int j = 0j < numbers.Lengthj++)
                        {

                            if (numbers[i] == numbers[j])
                            {
                                total++;
                                break;
                            }
                        }


                    }

                    return total;

                }

            }

Reactions

Post a Comment

0 Comments