Công thức: for i:=1 to n do if i mod 3 = 0 then s:=s+i;
VCT:
program phuongt; uses crt; var n, s, i: integer; begin clrscr; write(‘Nhap n = ‘); readln(n); s:=0; for i:=1 to n do if i mod 3 = 0 then s:=s+i; write(‘Tong cac so chia het cho 3 la: ‘, s); readln end.
program tong_chiahet_3;
uses crt;
var n,i,t:integer;
begin
clrscr;
write(‘Nhap n: ‘); readln(n);
t:=0;
for i:=1 to n do
if i mod 3=0 then t:=t+i;
write(‘Tong cac so chia het cho 3 tu 1 den ‘,n,’ la: ‘,t);
readln;
end.
Công thức: for i:=1 to n do if i mod 3 = 0 then s:=s+i;
VCT:
program phuongt;
uses crt;
var n, s, i: integer;
begin
clrscr;
write(‘Nhap n = ‘); readln(n);
s:=0;
for i:=1 to n do if i mod 3 = 0 then s:=s+i;
write(‘Tong cac so chia het cho 3 la: ‘, s);
readln
end.