第八行的表达式可更改,第三行的kexi决定的精度,小数值计算可将第五行的extended更为real或double
PROGRAM EQUANTION (input,output);
CONST
kexi=0.0000001;
VAR
a,b,c:extended;
FUNCTION fx(x:extended):extended;
BEGIN
fx:=ln(x)/ln(2);
END;
BEGIN
writeln('Please input a and b’,' Produced BY Chaos')
read(a,b);
c:=(a+b)/2;
IF fx(c)=0
THEN writeln('x=',c)
ELSE Repeat
IF fx(a)*fx(c)<0
THEN b:=c
ELSE a:=c;
UNTIL abs(a-b)<kexi;
IF fx(c)<>0
THEN writeln('x=',a);
END.