Invert Number

Please discuss general Delphi programming topics here.

Invert Number

Postby mouse » December 1st, 2003, 7:43 am

I am very New In Programming
I find Problem

How can I invert Number like 103 to 301

I am try But Need help
Code: Select all
program rr;
var y,x:integer;
begin
while y<>0  do
begin
readln(x);
y:= x mod 10;
writeln(y);
end;
x:=x div 10;
readln;
end;
Mouse @@@
mouse
Active Member
Active Member
 
Posts: 9
Joined: October 7th, 2003, 6:42 pm

Postby Johnny_Bit » December 1st, 2003, 1:47 pm

If you want to invert string representation of number in Delphi it's simple:

Code: Select all
var
  num, revnum, i:integer;
  s1, s2: string;
begin
  S1:=IntToStr(num);
  for I:=Length(S1) downto 1 do
    S2:=S2+S1[I]
  revnum:=strtoint(s2);
end;
Johnny_Bit
VIP Member
VIP Member
 
Posts: 455
Joined: June 15th, 2003, 9:56 am

Postby mouse » December 1st, 2003, 2:14 pm

Thanks
it`s simple but I am also beginner
Mouse @@@
mouse
Active Member
Active Member
 
Posts: 9
Joined: October 7th, 2003, 6:42 pm

Postby Kambiz » December 1st, 2003, 5:55 pm

And, for the integer values as follow:

Code: Select all
function MirrorNumber(Value: Integer): Integer;
begin
  Result := 0;
  while Value <> 0 do
  begin
    Result := Result * 10 + Value mod 10;
    Value := Value div 10;
  end;
end;
User avatar
Kambiz
Administrator
Administrator
 
Posts: 2408
Joined: March 7th, 2003, 7:10 pm


Return to Delphi Programming

Who is online

Users browsing this forum: No registered users and 1 guest

cron