uses crt; var n, d, s, k: longint; begin write (‘nhap n: ‘); readln (n); s:=0; d:=0; while (n <> 0 ) do begin k:=n mod 10; n:=n div 10; s:=s + k; end; writeln (‘tong cac chu so cua ‘,n,’ la: ‘,s); while n>0 do begin n:=n div 10; d:=d+1; end; writeln (‘so chu so cua ‘,n,’ la: ‘,d); readln; end.
uses crt;
var n,m:longint;
tong:byte;
BEGIN
clrscr;
write(‘Nhap n: ‘);
readln(n);
tong:=0;m:=n;
while m>0 do begin tong:=tong+m mod 10;
m:=m div 10;
end;
writeln(‘Tong cac chu so cua ‘,n,’ la: ‘,tong);
readln
END
Đếm số chữ:
Uses crt;
Var i,n,dem:longint;
Begin
ClrScr;
dem:=0;
Write(‘Nhap so nguyen n’);
ReadLn(n);write(‘so ‘,n,’ co ‘);
n:=abs(n);
while n>0 Do
Beginn :
= n div 10;
dem:=dem+1;
end;
writeln(dem,’ chu so’);
Readln
End
uses crt;
var n, d, s, k: longint;
begin
write (‘nhap n: ‘); readln (n);
s:=0;
d:=0;
while (n <> 0 ) do
begin
k:=n mod 10;
n:=n div 10;
s:=s + k;
end;
writeln (‘tong cac chu so cua ‘,n,’ la: ‘,s);
while n>0 do
begin
n:=n div 10;
d:=d+1;
end;
writeln (‘so chu so cua ‘,n,’ la: ‘,d);
readln;
end.