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.
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();
}
}
}
Comments
Leave a comment