编程论坛's Archiver

阳光跑道 发表于 2007-11-21 17:12

请教大家一个pascal问题

<P>下面是把一元钱换成1分,2分和5分有多少种换法的程序,在free pascal中,两个程序运行的结果不一样,其中第一个运行结果为461,第二个为404,请问大家知不知道是为什么?并且第一个用turbo pascal运行的结果为363,这又是为什么?希望有人帮助我,谢谢!<BR><BR>程序一:<BR>var<BR> s,x,y,z:integer;<BR> m:real;<BR>begin<BR> s:=0;<BR> for x:=1 to 100 do<BR>  for y:=1 to 50 do<BR>   for z:=1 to 20 do<BR>    begin<BR>     m:=0.01*x+0.02*y+0.05*z;<BR>     if m=1 then<BR>      begin<BR>       if s mod 5=0 then writeln;<BR>       write(' x=',x,' y=',y,' z=',z);<BR>       s:=s+1;<BR>      end;<BR>    end;<BR>   writeln;<BR>   write('s=',s);<BR>   readln;<BR>end.<BR><BR>程序二:<BR>var<BR> s,x,y,z:integer;<BR> m:real;<BR>begin<BR> s:=0;<BR> for x:=1 to 100 do<BR>  for y:=1 to 50 do<BR>   for z:=1 to 20 do<BR>    if 0.01*x+0.02*y+0.05*z=1 then<BR>     begin<BR>     if s mod 5=0 then writeln;<BR>     write(' x=',x,' y=',y,' z=',z);<BR>     s:=s+1;<BR>     end;<BR>   writeln;<BR>   write('s=',s);<BR>   readln;<BR>end.<BR></P>

阳光跑道 发表于 2007-11-26 08:06

怎么没有人回答??

页: [1]

Powered by Discuz! Archiver 6.1.0  © 2001-2007 Comsenz Inc.