PROGRAM AC_Circuit
!---------------------------------------------------------------------
! Program to compute the current in an a-c circuit containing a
! capacitor, an inductor, and a resistor in series.   Variables
! used are:
!    R     : resistance (ohms)
!    L     : inductance (henrys)
!    C     : capacitance (farads)
!    Omega : frequency (radians/second)
!    V     : voltage (volts)
!    Z     : total impedance
!    I     : current (amperes)
!
! Input:  R, L, C, Omega, and V
! Output: I
!---------------------------------------------------------------------

  REAL :: R, L, C, Omega
  COMPLEX :: V, Z, I

  PRINT *, "Enter resistance (ohms), inductance (henries), &
           &and capacitance (farads):"
  READ *, R, L, C

  PRINT *, "Enter frequency (radians/second):"
  READ *, Omega
  PRINT *, "Enter voltage as a complex number in the form (x, y):"
  READ *, V

! Calculate resistance using complex arithmetic
  Z = R +  Omega * L * (0.0, 1.0)  - (0.0, 1.0) / (Omega * C)

! Calculate and display current using complex arithmetic
  I = V / Z
  PRINT *
  PRINT 10, I, ABS(I)
  10 FORMAT(1X, "Current = ", F10.4, " + ",  &
            F10.4, "I" / 1X, "with magnitude = ", F10.4)
  
END PROGRAM AC_Circuit
