Tham khảo:
Program BTH;
uses crt;
var i,n,s:longint;
Begin
clrscr;
write('Nhap n: ');readln(n);
i:=1;
While i<>n do
Begin
If i mod 2=1 then s:=s+i;
i:=i+1;
end;
writeln('Tong day so tren la: ',s);
readln;
end.
Cách khác:
uses crt;
var n,i,t:integer;
begin
clrscr;
readln(n);
t:=0;
i:=1;
while (i<=n) do
begin
t:=t+i;
i:=i+2;
end;
writeln(t);
readln;
end.