var i,n,s:integer;
begin
readln(n);
s:=0;
for i:=1 to n do s:=s+1/i;
writeln(s:3:0);
end.
mình làm while do nhé, cái kia để mình tìm hiểu thêm
var S:real;
i,n:longint;
begin
writeln('n=') ; readln(n);
S:=0;
i:=1;
while (i<=n) do
begins=
S:= 9S+1/i;
i:=i+1;
end;
writeln ('S=');
end.
Câu 2:
program CTTTB;
uses crt;
var TB,x:real; n,y: integer;
begin
Write('Hay nhap so so thuc ban can tinh TB'); Readln(n);
for y:=1 to n do
begin Write('Nhap so thu',y);Readln(x);
TB:=TB+x;
end;
TB:=TB/n;
Writeln('Trung binh cong cua',n,' so nhap vao tu ban phim la',TB);
Readln;
End.