program hotrotinhoc;
var n,i.d: integer;
t: longint;
begin
readln(n);
t:=0; d:=0;
for i:=1 to n do
if i mod 3=0 then t:=t+i;
writeln('Tong cac so chia het cho 3 tu 1 den n la:',t);
for i:=1 to n do
if i mod 3=0 then inc(d);
write('Co ',d,' so chia het cho 3 tu 1 den N');
readln
end.
Bạn tham khảo nhé!
uses crt;
var a,b,t,i:integer;
begin
clrscr;
write('Nhap a='); readln(a);
write('Nhap b='); readln(b);
t:=0;
for i:=a to b do
if i mod 3=0 then t:=t+i;
writeln(t);
readln;
end.