Author Message

Hi, I have a problem of Turbo Pascal v.7. Can anyone help me to fix it.
Problem is how to provide the output when n is 3, 5, and 7. Please indicate
where's wrong and give me a solution. Thanks !

Program test;
var
NumArray : Array [1..7] of Integer;
i,j,k,r,q,c,n : Integer;

Procedure A (outarray:array of Integer;arrayno:Integer);
var
i:Integer;
Begin
for i:=0 to arrayno -1 do
write (outarray[i], ' ');
writeln;
End;
Function B (x,y : Integer):Integer;
Begin
B:=x div y;
End;
Begin
Write ('Enter a number: ');
if n > 0 then
Begin
NumArray[1]:=n;
k:=1;
Repeat
A(NumArray,k);
if NumArray [k]<> 1 then
Begin
NumArray [k]:=NumArray[k] -1 ;
NumArray [k+1]:=1;
k:=k+1;
End
else
Begin
c:=0;
i:=k;
while NumArray[i]=1
do
Begin
c:=c+1;
i:=i-1;
End;
Begin
NumArray[i]:=NumArray[i] -1;
q:=B(c+1,NumArray[i]);
r:=c+1 - q*NumArray[i];
j:=1;
while j=q
do
NumArray[i+1]:=NumArray[i];
i:=i+1;
j:=j+1;
End;
Begin
if r=0 then
k:=i;
k:=i+1;
NumArray[k]:=r;
end;
End;
until NumArray[1]=1;
End;
A(NumArray, n);
End.

Wed, 26 Nov 2003 19:13:53 GMT

 Page 1 of 1 [ 1 post ]

Relevant Pages