Answer to Question #294396 in C# for ITSyndicate

Question #294396

In C#, please.

Create a program that will accept inputs into 6x6 36-element two-dimensional

integer array Int2D6x6Array. 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:14:12-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[6,6];
            int count = 0;
            List<int> duplicateNumbers = new List<int>();


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

            for (int i = 0; i < 36; i++)
            {
                int i0 = i / 6;
                int j0 = i % 6;
                for (int j = i+1; j < arr.Length; j++)
                {
                    int i1 = j / 6;
                    int j1 = j % 6;
                    if (arr[i0, j0] == arr[i1, j1])
                    {
                        if (!duplicateNumbers.Contains(arr[i0, j0]))
                        {
                            duplicateNumbers.Add(arr[i0, j0]);
                            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