fortran小学生,请教各位这个fortran程序哪里不对,求解一元二次方程提示我Expected a right parenthesis in expression f=(-0.5*b/a,0.5*d/a)Expected a right parenthesis in expression g=(-0.5*b/a,0.5*d/a)programimplicit nonereal ::a,b

来源:学生作业帮助网 编辑:作业帮 时间:2024/04/20 18:19:21

fortran小学生,请教各位这个fortran程序哪里不对,求解一元二次方程
提示我Expected a right parenthesis in expression f=(-0.5*b/a,0.5*d/a)
Expected a right parenthesis in expression g=(-0.5*b/a,0.5*d/a)
program
implicit none
real ::a,b,c,d,e
complex f,g
print*,"please input a,b,c"
read*,a,b,c
d=abs(b*b-4*a*c)
e=sqrt(d)
f=(-0.5*b/a,0.5*e/a)
g=(-0.5*b/a,-0.5*e/a)
if (a/=0) then
print*,"one root is ",f
print*,"the other root is ",g
elseif ((a==0) .and.(b/=0)) then
print*," x=",-c/b
else
print*,"there are many roots"
endif
end program

program t !// Program 后面必须有名称,例如 t,不能是空的

implicit none

real :: a, b, c,d,e
complex f,g
print*, "please input a,b,c"
read*,a, b, c

d=abs(b*b-4*a*c)
e=sqrt(d)
f=cmplx(-0.5*b/a,0.5*e/a) !// 把两个数合成为复数,用 cmplx
g=cmplx(-0.5*b/a,-0.5*e/a) !// 同上
if (a/=0) then
print*, "one root is ", f
print*, "the other root is ", g
elseif ((a==0) .and. (b/=0)) then
print*, " x=", -c/b
else
print*, "there are many roots"
endif
end program