harish reddy

harish reddy

  • NA
  • 162
  • 30.8k

Array No of elemets

Jan 9 2018 2:07 AM
//Write a program in C# Sharp to count a total number of duplicate elements in an array.
Console.WriteLine("Enter first length");
int firstlength=int.Parse(Console.ReadLine());
int[] firstarray = new int[firstlength];
int k=0;
Console.WriteLine("Enter second length");
int secondlength = int.Parse(Console.ReadLine());
int[] secondarray = new int[secondlength];
int i, j;
for (i = 0; i < firstarray.Length; i++)
{
firstarray[i] = int.Parse(Console.ReadLine());
}
i = 0;
for (j = 0; j < secondarray.Length; j++)
{
secondarray[j] = firstarray[i];
i++;
Console.WriteLine(secondarray[j]);
}
for (i = 0; i < firstarray.Length; i++)
{
for (j = 0; j < secondarray.Length; j++)
{
if (firstarray[i] == secondarray[j])
{
k++;
}
}
k = 1;
}
 
Struck here pls help 

Answers (3)