I am having problems with a small amount of code that is in an array of arbitrary size with random number pairs, except for one that does not have a pair.
I need to find this number that does not have a pair.
arLength is the length of the array. but I am having problems with the actual match of the pairs and the search for one that does not have a pair.
for (int i = 0; i <= arLength; i++)
{
var number = nArray[i];
for (int e = 0; e <= arLength; e++)
{
if (e != i)
{
}
}
}
I also tried this:
var findValue = nArray.Distinct();
I searched around, but so far I have not been able to find a way to do this.
This code generates an array, but this question does not concern this part of the code, just for clarity.
Random num = new Random();
int check = CheckIfOdd(num.Next(1, 1000000));
int counter = 1;
while (check <= 0)
{
if (check % 2 == 0)
{
check = CheckIfOdd(num.Next(1, 1000000)); ;
}
counter++;
}
int[] nArray = new int[check];
int arLength = 0;
for (int i = 0; i < check; i++)
{
arLength = nArray.Length;
if (arLength == i + 1)
{
nArray[i] = i + 1;
}
else
{
nArray[i] = i;
nArray[i + 1] = i;
}
i++;
}
source
share