求助
请问我下面的程序,build时并没有问题,但是运行时一直运行不出来(就是我按回车他没有反应)。请问我下面的程序是有什么问题吗
[Fortran] 纯文本查看 复制代码 program main
implicit none
external roots1
external roots2
integer::x,y
real::a,b,c,m,n
write(*,*) "please input two positive numbers"
read(*,*) x,y
a=real(x)
b=real(y)
call roots2(a,b,c)
write(*,*) "the first root:"
call roots1(a,c,m)
write(*,*) "the second root:"
call roots1(c,b,n)
end program
subroutine roots1(a,b,c)
implicit none
real,intent(in)::a,b
real::p,q
real,intent(out)::c
p=a
q=b
do
if(f1(p)*f1(q)<0)then
c=(p+q)/2
if(abs(f1(c))<0.0000001)then
write(*,100) c
100 format(F10.4)
exit
elseif(f1(p)*f1(c)<0)then
q=c
else
p=c
end if
end if
end do
contains
real function f1(x)
implicit none
real,intent(in)::x
f1=x**3-5*x+3
end function
end subroutine
subroutine roots2(a,b,c)
real,intent(in)::a,b
real::p,q
real,intent(out)::c
p=a
q=b
do
if(f2(p)*f2(q)<0)then
c=(p+q)/2
if(abs(f2(c))<0.0000001)then
c=(p+q)/2
exit
elseif(f2(p)*f2(c)<0)then
q=c
else
p=c
end if
end if
end do
contains
real function f2(x)
implicit none
real,intent(in)::x
f2=3*x**2-5
end function
end subroutine
|