pascal错在哪

来源:百度知道 编辑:UC知道 时间:2024/05/19 09:17:24
var z,x,c:real;
begin
for z:=-100to 100do
for x:=-100to 100do
for c:=-100to 100do
if 3*z+2*x+c=10 and 3*x+2*c+z=10 and 3*c+2*z+x=10
then write('z=',z,'x='x'c='c);
end.

运行后出现error97

real如果作为循环变量,那你觉得是以1为循环分类,还是0.01呢?或者更小?
所以,记住,以后循环变量千万不要用real

real不能当循环变量,应把z,x,c该为integer。

var
z, x, c: integer;
begin
for z:= -100 to 100 do
for x:= -100 to 100 do
for c:= -100 to 100 do
if (3*z+2*x+c=10) and (3*x+2*c+z=10)
and (3*c+2*z+x=10) then
write('z='+IntToStr(z)+' x='+IntToStr(x)+
' c='+IntToStr(c));
end.