0
I have been trying for a long time to produce a code that identifies and reports to the user if there are repeated elements in a 5x5 matrix, composed of random numbers, in the pascal. I’ve tried searching the matrix using one or two variables and also with an entire matrix for research, but it didn’t work. I have heard, from some people, that it is not necessary a very large code, nor too complex for the task. Thus my despair increases.
I ask if anyone has any solution to the problem
Pastebin link to unsuccessful attempt (and most traveled)- https://pastebin.com/uzPLACXe
Code:
program Exercicio5;
var
Matr, same: array [1..5, 1..5] of real;
lin, col, linPesq, ColPesq:integer;
repete: boolean;
begin
randomize;
for lin:= 1 to 5 do
begin
writeln;
for col:= 1 to 5 do
begin
Matr[lin, col]:= random (1000);
same[lin,col]:= Matr[lin,col];
write(Matr[lin, col]:0:2, ' | ');
end;
end;
for LinPesq:= 1 to 5 do
begin
for ColPesq:= 1 to 5 do
begin
for lin:= 1 to 5 do
begin
for col:= 1 to 5 do
begin
if same[LinPesq,ColPesq] = Matr[lin, col] then
begin
if lin and col and LinPesq and ColPesq <> 1 then
begin
repete := true;
break;
end;
end;
end;
end;
end;
end;
writeln;
writeln;
if repete = true then
writeln('Ha elementos repetidos na matriz')
else
writeln('Nao ha elementos repetidos na matriz');
readln;
end.
hello, put your code here to enhance the view
– Ricardo Pontual