# Find the minimal natural number m formed with the same digits?

ok so im trying to write a simple program that does the following:

For a given natural number n find the minimal natural number m formed with the same digits. E.g. n=3658, m=3568.

i am a total noob at pascal and programming. i was close to figuring out average but i couldnt manage. could you guys help me?

• : ok so im trying to write a simple program that does the following:
:
: For a given natural number n find the minimal natural number m
: formed with the same digits. E.g. n=3658, m=3568.
:
:
: i am a total noob at pascal and programming. i was close to figuring
: out average but i couldnt manage. could you guys help me?
:
:
[code][color=Blue]procedure process(n:longint);
var s:string;
l:byte absolute s; { length of s, auto updating }
i,j:byte;
procedure swap(var a,b:char); { Swaps two characters }
var c:char;begin c:=a;a:=b;b:=c;end;
begin
str(n,s); { Convert integer to string }
if l>1 then

for i:=l downto 2 do { Simple bubble sort, ascending order }
for j:=1 to i do
end;

var s:string;
err:integer;
n:longint;

begin
repeat
repeat
write('Enter a positive integer ( 0 to quit ) :');readln(s);
val(s,n,err);
if ((err<>0) or (n>2147483647) or (n<0)) then writeln('Invalid entry, try again.'#13#10);
until ((n>=0) and (err=0));
if n>0 then process(n);
until (n=0);
end.[/color][/code]