: i am working a program with pascal. This program have to write all the possibility combinations which one can get from (1,2,3,4,5,6,7,8)
: Note: These are not stored in an array
:
: Each combination must be made up with all the 8 numbers and repetitions of numbers are not allowed
:
You should use a recursive algorithm. Here's an untested example:
procedure OutputCombinations(Out: string);
begin
if Length(Out) = 8 then
writeln(Out)
else begin
for i := 1 to 8 do
begin
if Pos(IntToStr(i), Out) = 0 then
Out := Out + IntToStr(i);
OutputCombinations(Out); // Add next number
end;
end;
If IntToStr() doesn't exist, then you can write your own using the Str() procedure.