0 bình luận về “viết chương trình tính tổng S=3+6+9+…+3n”
uses crt; var n,i,s:integer; begin clrscr; i:=0; write(‘Nhap n: ‘); readln(n); n:=n*3; while i<=n do begin inc(s,i); inc(i,3); end; write(s); readln; end.
program phuongt; uses crt; var s, n, i: integer; begin clrscr; write(‘Nhap n = ‘); readln(n); n:=3*n; i:=3; while i<=n do begin if i mod 3 = 0 then s:=s+i; i:=i+1; end; write(‘S = ‘, s); readln
uses crt;
var n,i,s:integer;
begin
clrscr;
i:=0;
write(‘Nhap n: ‘); readln(n);
n:=n*3;
while i<=n do
begin
inc(s,i);
inc(i,3);
end;
write(s);
readln;
end.
program phuongt;
uses crt;
var s, n, i: integer;
begin
clrscr;
write(‘Nhap n = ‘); readln(n);
n:=3*n;
i:=3;
while i<=n do
begin
if i mod 3 = 0 then s:=s+i;
i:=i+1;
end;
write(‘S = ‘, s);
readln
end.