lundi 30 juillet 2018

C# Referring to for-loop variable in if-statement

Can I refer to the variable I assigned to in the for-loop in an if-statement that is embedded in the loop? My plan was to iterate through the numberFactorList with the loop variable, but I am getting very strange output. With this input: 1,2,1,3,1,2,4,1,2,3,6,1,2,3,4,6,12 I am getting 2 and 4. With 1,2,1,5,1,2,5,10 I am getting 2 and 10 and so on. However, I want to only filter those numbers that are between two ones. What am I doing wrong?

for (int a = 0; a < numberFactorLength - 2; a++)
        {
        if (numberFactorList[a] + numberFactorList[a+1] + numberFactorList[a+2] == numberFactorList[a+1] + 2)
            {
                primeNumberList.Add(factorList[a + 1]);
            }
        }

I am still a beginner. Thank you!

Aucun commentaire:

Enregistrer un commentaire