Arrays of different lengths and consist of numbers. It is necessary to find the same elements and display.

  • Repetitive elements to print or not? - avp

2 answers 2

f(int a[], int b[]) { print (intersect (a, b)) ; } 

What is the question, is the answer.

    Since the language is not known, the algorithm is:

     Масив А \\Первый масив Масив Б \\Второй масив Масив В \\Массив в которм будут результат числа : i : счетчик для массива А j : счетчик для массива Б C : счетчик для массива В c := 1; for i= 1 to длина массива А do begin for j = 1 to длинна массива Б do begin if A[i] = Б[j] then // сравниваем значения и если совпало то выполняем begin B[c] := A[c]; c := c + 1; end; end; end; 

    Well, here we derive B in the screen.

    This is a mixture of Russian and Pascal ^)

    • And if there are more than one identical elements? Say, two units in array A and five in array B? How many units will then be in array B? Also it is not indicated how to allocate memory for the array B =) - gecube
    • one figure, I think enough - MAMN54
    • By the way, thanks, I think it will come in handy on pascal) - MAMN54
    • The bottom line is that when I wrote the answer, the question was not according to the language not according to the conditions. I just wrote one of the solutions to the problem, in a mixture of Russian and Pascal. - SoftR
    • @gecube I did not write the working code, but showed only a solution to the problem. If in A 2 fields 1 and in B 5 fields 1 then in B there will be 10 fields with 1. Nobody, when setting the task, set the task unique. - SoftR