The task is to find duplicate words in the array and display them. I decided to implement it like this:

for i:=1 to 30 do for i1:=1 to 30 do if w[i1]=w[i] then begin write(w[i],' '); break; end; 

But the original array is displayed completely, without any changes. What is the problem?

    1 answer 1

    The problem is that for any element number in the code there will be a moment when both i and i1 are equal to it, and at the same time. Well, if w [i1] = w [i] works (why would an element not be equal to itself?) - here's the output of all the elements.

    It is necessary to exclude such a "crossing". And at the same time exclude two checks of each pair (in direct and reverse orders). Best of all:

     for i:=1 to 29 do for i1:=1+i to 30 do