12-01-2007, 06:17 PM
program adding_commas; (* add commas in a string 12,345,678.90*)
uses crt;
var s1,s2,ip,dp : string;
L : integer;
procedure Fdot(var stg:string); (* finding dot *)
var p: integer;
begin
p:= pos('.',stg);
if p>0 then
begin
ip:=copy(stg,1,p-1);
dp:=copy(stg,p,length(stg)-p+1)
end else
writeln('It is an integer')
end;
procedure addcommas(var stg:string);
var s: string; y: integer;
begin
s:='';
for y:=length(stg) downto 1 do
begin
if (y mod 3)=0 then s:=','+stg[y]+s else
s:=stg[y]+s
end;
stg:=s
end;
Begin
readln(s2);
fdot(s2);
writeln(ip,dp);
addcommas(ip);
writeln(ip,dp);
End.
uses crt;
var s1,s2,ip,dp : string;
L : integer;
procedure Fdot(var stg:string); (* finding dot *)
var p: integer;
begin
p:= pos('.',stg);
if p>0 then
begin
ip:=copy(stg,1,p-1);
dp:=copy(stg,p,length(stg)-p+1)
end else
writeln('It is an integer')
end;
procedure addcommas(var stg:string);
var s: string; y: integer;
begin
s:='';
for y:=length(stg) downto 1 do
begin
if (y mod 3)=0 then s:=','+stg[y]+s else
s:=stg[y]+s
end;
stg:=s
end;
Begin
readln(s2);
fdot(s2);
writeln(ip,dp);
addcommas(ip);
writeln(ip,dp);
End.