# Problems in Printing combinations of numbers

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

• : 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:
[code]
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);
end;
end;
[/code]
If IntToStr() doesn't exist, then you can write your own using the Str() procedure.

• : You should use a recursive algorithm. Here's an untested example:
: [code]
: 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;

Yes But I have to be restricted in using eight loops in order to form all possible numbers
: [/code]
: If IntToStr() doesn't exist, then you can write your own using the Str() procedure.
:

• :
: : You should use a recursive algorithm. Here's an untested example:
: : [code]
: : 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;
:
:
:
:
: Yes But I have to be restricted in using eight loops in order to form all possible numbers
: : [/code]
: : If IntToStr() doesn't exist, then you can write your own using the Str() procedure.
: :
:
:
This produces 8 loops, since the function is only called 8 times: once for each number in the sequence.