Câu 1:
uses crt;
var n,t,ch,dv,tr:longint;
begin
clrscr;
write('n='); readln(n);
if (100<=n) and (n<=999) then
begin
dv:=n mod 10;
ch:=n div 10; ch:=ch mod 10;
tr:=n div 100; tr:=tr mod 10;
t:=dv+ch+tr;
writeln('tong 3 chu so cua so ',n,' la: ',t);
end
else writeln('vui long nhap so co 3 chu so');
readln;
end.
Câu 2:
uses crt;
var a,b,tam:longint;
begin
clrscr;
write('a='); readln(a);
write('b='); readln(b);
writeln('gia tri ban dau cua a la: ',a);
writeln('gia tri ban dau cua b la: ',b);
tam:=a;
a:=b;
b:=tam;
writeln('gia tri sau khi doi cua a la: ',a);
writeln('gia tri sau khi doi cua b la: ',b);
readln;
end.
Câu 1:
var n,t,i,s:integer;
begin
write('Nhap so n: ');
readln(n);
t:=n;
for i:=1 to 3 do
begin s:=s+t mod 10;
t:=t div 10; end;
write('Tong cac chu so cua ',n,' la: ',s);
end.
Câu 2:
var a,b,t:integer;
begin
write('Nhap a: ');
readln(a);
write('Nhap b: ');
readln(b);
if a>b then begin t:=a;
a:=b;
b:=t; end;
write('a=',a,' b=',b);
end.