Question
PROGRAM Quadratic_equation1 ! This program the roots of the quadratic equation using the ! quadratic formula ! ! Constant: epsilon ! Variables: a,b,c,discriminant, root1, root2
PROGRAM Quadratic_equation1
! This program the roots of the quadratic equation using the
! quadratic formula
!
! Constant: epsilon
! Variables: a,b,c,discriminant, root1, root2
! discriminant=b**2 - 4.0*a*c
! Input: Coefficients of the quadratic equation a,c and c
! Output: a,b,c, epsilon, discriminant, root 1, root 2
!
IMPLICIT NONE
! Constant declaration
REAL, PARAMETER ::epsilon=1E-6
!Variables declaration
REAL::a.b.c. discriminant, sqrt_discriminant,root1,root 2
!Read in the input
PRINT*, "Enter the three coefficient a,b, and c:"
READ*,a,b,c
! Test if a equals zero. if yes, exit the program
IF (a.LT.epsilon)THEN
PRINT*,"The value of a is zero. Execution terminated"
STOP
END IF
discriminant=b**2-4*a*c
PRINT*, "The coefficient are:", a,b,c
PRINT*, "The value of the discriminant is", discriminant
! Check if the discriminant is negative.
! If it is, print message and stop the program
IF (discriminant .LT.0.0)THEN
PRINT*, "Discriminant is negative. The are no REAL roots"
STOP
END IF
!Check if the discriminant is zero
!If it is, calculate and print the single real root
!Otherwise calculate and print the two real roots
IF abs(discriminant) root1=b**2/2.0*a PRINT*,"The root is", root 1 ELSE sqrt_discriminant=SQRT(discriminant) root1=(-b + sqrt_dsicriminant)/(2.0*a) root2=(-b - sqrt_discriminant)/(2.0*a) PRINT*,"The roots are",root1,root2 END IF END PROGRAM Quadratic_equation1 Question:
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started