- #1
mike81
- 6
- 0
I am trying to write this program, it runs fine but I can't get the imaginary numbers to print correctly. I have been trying this for a few hours now and can't figure it out. Here is the code, I am running Force 2.0. Thanks in advance for the help.
Program Quad
Implicit None
Real Root1, Root2, a, b, c, discri
Complex Croot1, Croot2
2 Write (*,*) 'Enter 3 numbers'
Read (*,*) a,b,c
discri=(b**2-(4*a*c))
If (discri.lt.0) Then
Write (*,*) 'Roots are Complex'
Croot1=(-b+SQRT(abs(b**2-4*a*c))/2*a)
Croot2=(-b-SQRT(abs(b**2-4*a*c))/2*a)
Write (*,*) 'Root 1 is',Croot1
Write (*,*) 'Root 2 is',Croot2
Else
Write (*,*) 'Roots are Real'
Root1=(-b+SQRT(abs(b**2-4*a*c))/2*a)
Root2=(-b-SQRT(abs(b**2-4*a*c))/2*a)
Write (*,*) 'Root 1 is',Root1
Write (*,*) 'Root 2 is',Root2
End If
Goto 2
End
Program Quad
Implicit None
Real Root1, Root2, a, b, c, discri
Complex Croot1, Croot2
2 Write (*,*) 'Enter 3 numbers'
Read (*,*) a,b,c
discri=(b**2-(4*a*c))
If (discri.lt.0) Then
Write (*,*) 'Roots are Complex'
Croot1=(-b+SQRT(abs(b**2-4*a*c))/2*a)
Croot2=(-b-SQRT(abs(b**2-4*a*c))/2*a)
Write (*,*) 'Root 1 is',Croot1
Write (*,*) 'Root 2 is',Croot2
Else
Write (*,*) 'Roots are Real'
Root1=(-b+SQRT(abs(b**2-4*a*c))/2*a)
Root2=(-b-SQRT(abs(b**2-4*a*c))/2*a)
Write (*,*) 'Root 1 is',Root1
Write (*,*) 'Root 2 is',Root2
End If
Goto 2
End