S
S
Sergey Panov2018-06-01 13:39:01
C++ / C#
Sergey Panov, 2018-06-01 13:39:01

How to compare 9 elements with 14?

Good afternoon. I didn't come up with a more understandable name for the topic :)
I have 9 elements in the RandomSym array. I need to compare them with the AllSym array, which contains 14 elements.
That is : If the 0 element of RandomSym is equal to the 0 element of AllSym, then the loop continues, and if not, the loop index should return RandomSym the same number so that it compares again the 0 element of RandomSym with the already 1 element (other in order) AllSym.
Please tell me how to implement so that RandomSym checks until it finds an equal one in AllSym and only then moves on to another RandomSym index.
The code:

void Hint()
        {
        int tempHint = 0;
            while (tempHint <= RandomSym.Length)
            {
                if (RandomSym[tempHint] == AllSym[tempHint])
                {
                    //если равно, пишем код и прибавляем tempHint
                    tempHint++;
                }
            }
        }

Many thanks in advance for your help.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
P
Peter, 2018-06-01
@select8

So?

static void Main(string[] args)
        {
            int[] RandomSum = new int[9] {1,5,4,8,7,3,0,8,9};
            int[] AllSum = new int[14] { 1, 5, 4, 8, 7, 3, 0, 8, 9, 1, 5, 4, 8, 7};

            int count = 0;

            for (int i = 0; i < RandomSum.Length; i++)
            {
                for (int j = 0; j < AllSum.Length; j++)
                {
                    if(RandomSum[i] == AllSum[j])
                    {
                        count++;
                        
                    }
                    
                }
            }

            Console.WriteLine($"Количество совпадении {count}");
            Console.ReadKey();
        }

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question