👤

calculati suma primelor n termene 1-1/2+1/3-1/4+1/5-1/6+....
Indicatii:Utilizati in ciclul instructiunea if odd(...) the ... else...


Răspuns :

program Tema;
Var i,n:integer
      s:real;
begin

read(n);
i:=1;
s:=0.0;
while(i<=n) do
begin
if(odd(i)) then
s:=s+1.0/i;
else
s:=s-1.0/i;

i:=i+1;
end;
writeln('Suma ceruta este: ',s);
end.