program subPrograms (input,output);

 

{ This version works if the strings are both on the same line }

{ but not if they are on two separate lines - carriage return is a character }

 

type mystring = packed array[1..5] of char;

 

var astring1, astring2 : mystring;

    answer         : boolean;

 

procedure swap (var character1, character2 : char);

var temp : char;

begin

   temp := character1;

   character1 := character2;

   character2 := temp;

  

end;

 

procedure sort (var astring: mystring);

 

var i,j : integer;

 

begin

    for j := 1 to 5 do

      for i := 1 to 4 do

       if astring[i] > astring[i+1] then

          swap (astring[i], astring[i+1]);

end;

 

 

 

function check (string1,string2 : mystring) : boolean;

begin

   check := false;

   if (string1 = string2) then

      check := true;

end;

 

begin

  writeln;

  writeln (' This program will obtain 2 character strings of length <= 5 from user.');

  writeln (' It will echo back the strings; determine if they are anagrams of each other; ');

  writeln (' and tell the user whether they are or not. ');

  writeln ;

 

  writeln ('Please enter two - 5 character strings on the same line ');

  writeln ('with no spaces between them.');

  read (astring1, astring2);

  writeln ('data you entered is ', astring1 , '   ',  astring2);

  sort (astring1);

  writeln (astring1);

  sort (astring2);

  writeln (astring2);

  answer:= check (astring1, astring2);

  if(answer) then

    writeln (' the two strings are anagrams of each other ')

  else

    writeln (' the two strings are not anagrams of each other '); 

end.