Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Buy a domain name - Register cheap domain names from $0.99 - Namecheap

Scalable Hosting That Grows With You

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Semrush - keyword research tool

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

39,845 questions

51,766 answers

573 users

How to remove duplicates from an array in Pascal

1 Answer

0 votes
program RemoveDuplicatesAndPrintProgram;

var
  arr: array[1..17] of Integer;
  uniqueArr: array[1..17] of Integer = (0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0);
  size, i, j, uniqueCount: Integer;
  found: Boolean;

begin
  size := 17; // Number of elements in the array
  arr[1] := 1; arr[2] := 3; arr[3] := 4; arr[4] := 3; arr[5] := 3; 
  arr[6] := 4; arr[7] := 1; arr[8] := 1; arr[9] := 5; arr[10] := 5; 
  arr[11] := 6; arr[12] := 7; arr[13] := 8; arr[14] := 8; arr[15] := 8; 
  arr[16] := 8; arr[17] := 9;
  
  uniqueCount := 0;
  
  for i := 1 to size do
  begin
    found := False;
    for j := 1 to uniqueCount do
    begin
      if arr[i] = uniqueArr[j] then
      begin
        found := True;
        Break;
      end;
    end;
    if not found then
    begin
      Inc(uniqueCount);
      uniqueArr[uniqueCount] := arr[i];
    end;
  end;
  
  for i := 1 to uniqueCount do
    Write(uniqueArr[i], ', ');
  WriteLn;
end.



(*
run:

1, 3, 4, 5, 6, 7, 8, 9, 

*)

 



answered Jan 28, 2025 by avibootz
...