Answer to Question #294394 in C# for ITSyndicate

Question #294394

In C# please.

Create a program that will accept inputs into 25-element one-dimensional integer

array IntArray. Your program should count the duplicate numbers appeared in the list of

accepted values. Moreover, you are also tasked to display the duplicate numbers that

appeared in the list.


1
Expert's answer
2022-02-06T02:13:48-0500
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp2
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] arr= new int[25];
            int count = 0;
            List<int> duplicateNumbers = new List<int>();

            Random r = new Random();
            for (int i = 0; i < arr.Length; i++)
            {
                Console.WriteLine("Input {0} number :", i + 1);
                arr[i] = Convert.ToInt32(Console.ReadLine());
            }

            for (int i = 0; i < arr.Length; i++)
            {
                for (int j = i+1; j < arr.Length; j++)
                {
                    if (arr[i] == arr[j])
                    {
                        if (!duplicateNumbers.Contains(arr[i]))
                        {
                            duplicateNumbers.Add(arr[i]);
                            count++;
                        }
                    }
                }
            }

            Console.WriteLine("Duplicate count: {0}", count);
            Console.WriteLine("Duplicate numbers:");

            for (int i = 0; i < duplicateNumbers.Count; i++)
            {
                Console.WriteLine(duplicateNumbers[i]);
                
            }
            Console.ReadKey();
        }
    }
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS