求大神帮助,哪错了???

P1035 [NOIP2002 普及组] 级数求和

天道酬勤 @ 2017-01-07 11:28:12

为什么运行有错误?????????

var
 n,ans:integer;
 K,sni:real;
begin
 readln(K);
 ans:=0;
 n:=1;
 sni:=0.0;
 while sni<=K do
  begin
   sni:=sni+1/n;
   n:=n+1;
   ans:=ans+1;
  end;
 writeln(ans);
end.

by 南橙未熟k @ 2017-01-18 13:32:23

可以这样

var n,k,i:longint;t:real;
begin
readln(n);
repeat
inc(k);
t:=t+1/k;
until t>n;
writeln(k);
end.

|