Can someone give him a head start re: the following Q:(adsbygoogle = window.adsbygoogle || []).push({});

We can make the program test itself by having it plug in the found root and evaluate the LHS (it should be zero). Complete the program by having it evaluate the LHS at x = root1.

! This program finds the roots of equations of the 2nd degree

! with coefficients a, b and c

program Equation

implicit none

real*4 a, b, c, delta

real*4 root1, root2

integer*1 count

! ----------------------------------------------Prompt and Input

print*, "Solves ax^2 + bx + c = 0"

print*, "Enter the coefficients a,b,c separated by commas..."

read*, a, b, c

! ----------------------------------------------Validate

! ----------------------------------------------Find delta

delta = b**2 - 4.* a * c

! ----------------------------------------------Determine Roots

if (delta .GT. 0.) then

root1 = (-b + sqrt(delta)) / (2. * a)

root2 = (-b - sqrt(delta)) / (2. * a)

count = 2

else if (delta .LT. 0.) then

count = 0

else

root1 = -b / (2. * a)

count = 1

end if

! ----------------------------------------------Show Results

if (count .EQ. 2) then

write(*,20) " Equation has two roots: ", root1, ", ", root2

else if (count .EQ. 1) then

write(*,20) " Equation has one root: ", root1

else

write(*,20) " Equation has no real roots!"

end if

20 format(1x, A, F10.4, A, F10.4)

! ----------------------------------------------Verify root1

if (count .GT. 0) then

print*, "Verifying the first root by computing the L.H.S.:"

end if

! ----------------------------------------------

end

**Physics Forums - The Fusion of Science and Community**

The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

# Beginner Fortran Help

Loading...

Similar Threads - Beginner Fortran Help | Date |
---|---|

Fortran question (beginner) | Oct 28, 2015 |

Help for fortran 90 beginner | Jan 23, 2014 |

FORTRAN PROGRAM FOR MEANS (Beginner) | Mar 9, 2013 |

FORTRAN codes for beginners | Feb 5, 2011 |

Beginner fortraner: messing up arithmatic | Sep 29, 2008 |

**Physics Forums - The Fusion of Science and Community**