uses crt; var n:integer; {Ham tong} function s(k:integer):longint; begin s:=0; while k>0 do begin s:=s+(k mod 10); k:=k div 10; end; end; {Ham tich} function p(k:integer):longint; begin p:=1; {nếu khai báo p:=0 thì nhân ra vẫn =0} while k>0 do begin p:=p*(k mod 10); k:=k div 10; end; end; {Chuong trinh chinh} begin clrscr; write(‘Nhap n: ‘); readln(n); writeln(‘Tong: ‘,s(n)); write(‘Tich: ‘,p(n)); readln; end.
program tong_Tich;
uses crt;
var n:longint;
{—TONG—}
function tong(k:longint):integer;
begin
tong:=0;
while k>0 do
begin
tong:=tong+(k mod 10);
k:=k div 10;
end;
end;
{—TICH—}
function tich(k:longint):integer;
begin
tich:=1;
while k>0 do
begin
tich:=tich*(k mod 10);
k:=k div 10;
end;
end;
{—CT-chinh—}
BEGIN
clrscr;
write(‘Nhap n: ‘); readln(n);
writeln(‘Tong cac chu so cua ‘,n,’ la: ‘,tong(n));
writeln(‘Tich cac chu so cua ‘,n,’ la: ‘,tich(n));
readln;
end.
uses crt;
var n:integer;
{Ham tong}
function s(k:integer):longint;
begin
s:=0;
while k>0 do
begin
s:=s+(k mod 10);
k:=k div 10;
end;
end;
{Ham tich}
function p(k:integer):longint;
begin
p:=1; {nếu khai báo p:=0 thì nhân ra vẫn =0}
while k>0 do
begin
p:=p*(k mod 10);
k:=k div 10;
end;
end;
{Chuong trinh chinh}
begin
clrscr;
write(‘Nhap n: ‘); readln(n);
writeln(‘Tong: ‘,s(n));
write(‘Tich: ‘,p(n));
readln;
end.