Fortran编写二分法, 软件说有一个错误,我不知道那里有问题,请高手解答,谢谢!
程序编写如下program1implicitnonerealx,a,b,c,wcrealfa,fcrealf(x)print*,"Pleaseputinthetwonum...
程序编写如下
program 1
implicit none
real x,a,b,c,wc
real fa,fc
real f(x)
print*,"Please put in the two numbers between which you guess the outcome is"
read*,a,b
wc=5
f(x)=x*x-2*x-7
do while (b-a<wc)
c=(b-a)/2
fa=f(a)
fc=f(c)
if (fa * fc <0) then
b=c
else
a=c
end if
end do
write(*,*) a
end 展开
program 1
implicit none
real x,a,b,c,wc
real fa,fc
real f(x)
print*,"Please put in the two numbers between which you guess the outcome is"
read*,a,b
wc=5
f(x)=x*x-2*x-7
do while (b-a<wc)
c=(b-a)/2
fa=f(a)
fc=f(c)
if (fa * fc <0) then
b=c
else
a=c
end if
end do
write(*,*) a
end 展开
2个回答
展开全部
“real f(x)”有这样定义函数的么?
program lin182838
implicit none
real x,a,b,c,wc
real fa,fc
print*,"Please put in the two numbers between which you guess the outcome is"
read*,a,b
wc=5
do while (b-a<wc)
c=(b-a)/2
fa=f(a)
fc=f(c)
if (fa * fc <0) then
b=c
else
a=c
end if
end do
write(*,*) a
contains
real function f(x)
real::x
f= x*x-2*x-7
end function
program lin182838
implicit none
real x,a,b,c,wc
real fa,fc
print*,"Please put in the two numbers between which you guess the outcome is"
read*,a,b
wc=5
do while (b-a<wc)
c=(b-a)/2
fa=f(a)
fc=f(c)
if (fa * fc <0) then
b=c
else
a=c
end if
end do
write(*,*) a
contains
real function f(x)
real::x
f= x*x-2*x-7
end function
更多追问追答
追问
啊……好久不用忘记了……
不过改了之后还是显示有一处错误
还能再看看哪里错了吗?谢谢!
追答
错误贴出来,要不就是你“program 1”错了。后面要跟字母开头“program lin182838”
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
最后少个end和program对应,漏贴了,呵呵
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询