第八行的表达式可更改,第三行的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.
二分法求函数值的Pascal实现,布布扣,bubuko.com
原文地址:http://www.cnblogs.com/Chaobs/p/3837469.html