*Tổng số nguyên chẵn:
- Công thức: for i:=1 to n do if i mod 2=0 then t:=t+i;
- Chương trình:
program tong_chan;
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 2=0 then t:=t+i;
write('Tong cac so chan tu 1 den n la: ',t);
readln;
end.
*Tổng số nguyên:
- Công thức: for i:=1 to n do t:=t+i;
- Chương trình:
program tong_so;
uses crt;
var n,i,t:integer;
begin
clrscr;
write('Nhap n: '); readln(n);
t:=0;
for i:=1 to n do t:=t+i;
write('Tong cac so nguyen tu 1 den n la: ',t);
readln;
end.