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,844 questions

51,765 answers

573 users

How to print a set in Pascal

2 Answers

0 votes
program PrintElementInSet;

type
  TMySet = set of 1..10; // Define a set with elements from 1 to 10

var
  MySet: TMySet;
  i : Integer;

begin
  MySet := []; // Initialize the set as empty
  Include(MySet, 1); // Insert the element 1 into the set
  Include(MySet, 2); // Insert the element 2 into the set
  Include(MySet, 5); // Insert the element 5 into the set
  Include(MySet, 6); // Insert the element 6 into the set

  for i := Low(TMySet) to High(TMySet) do
    if i in MySet then
      WriteLn('Set contains: ', i);
end.




(*
run:
  
Set contains: 1
Set contains: 2
Set contains: 5
Set contains: 6

*)

 



answered Aug 5, 2025 by avibootz
0 votes
program PrintElementInSet;

type
  TColor = (Red, Green, Blue, Yellow);
  TColorSet = set of TColor;

procedure PrintColorSet(const ASet: TColorSet);
const
  ColorNames: array[TColor] of String = ('Red', 'Green', 'Blue', 'Yellow');
var
  color: TColor;
  FirstElement: Boolean;
begin
  Write('[');
  FirstElement := True;
  for color := Low(TColor) to High(TColor) do
  begin
    if color in ASet then
    begin
      if not FirstElement then
        Write(', ');
      Write(ColorNames[color]);
      FirstElement := False;
    end;
  end;
  Writeln(']');
end;

var
  MyColors: TColorSet;

begin
  MyColors := [Red, Green];
  PrintColorSet(MyColors); 

  MyColors := [Green, Blue, Red];
  PrintColorSet(MyColors); 

  MyColors := []; // Empty set
  PrintColorSet(MyColors); 
end.



(*
run:
  
[Red, Green]
[Red, Green, Blue]
[]

*)

 



answered Aug 5, 2025 by avibootz
...