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?

Comments

  • : 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[10];
    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
    if ord(s[i])');readln;
    end;


    var s:string[10];
    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]
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

In this Discussion