program main
implicit none
real, parameter :: epsilon=1e-6
real :: xa,xb,xc,a
real,external :: f
a=1.0
do while(a>0)
write(*,*) "it is the first time or f(xa)*f(xb)>0"
write(*,*) "please input proper xa and xb"
read(*,*) xa,xb
write(*,*) f(xa),f(xb)
if(f(xa)*f(xb)<=0) exit
end do
do while (xb-xa>epsilon)
xc=(xa+xb)/2
if (f(xa)*f(xc)<0) then
xb=xc
else
xa=xc
end if
end do
xc=(xa+xb)/2
write(*,*) "the solution is:",xc
end
本内容试读结束,登录后可阅读更多
下载后可阅读完整内容,剩余1页未读,立即下载