用fortran:输入系数a、 b、 c, 求解一元二次方程ax2+bx+c=0的根
时间: 2023-12-25 11:09:22 浏览: 232
LqrSim:通过 C+Fortran 在 Simulink 中求解代数 Riccati 方程-matlab开发
好的,可以直接给您提供代码:
program quad_eq
implicit none
real*4 :: a, b, c, discriminant, x1, x2
print *, "Please input coefficients a, b, and c: "
read *, a, b, c
discriminant = b**2 - 4.0*a*c
if (discriminant < 0.0) then
print *, "Sorry, the roots are complex."
else
x1 = (-b + sqrt(discriminant)) / (2.0*a)
x2 = (-b - sqrt(discriminant)) / (2.0*a)
print *, "The roots are:", x1, "and", x2
endif
end program quad_eq
阅读全文