! Program Example from "Essential Fortran 90 & 95" by Loren P. Meissner
! Copyright 1996. Copying for sale requires permission from the author.
! Otherwise, distribution is permitted if these three lines are included.

! Example 1.3. Rational Powers of a Complex Number.
  program B03
    implicit none  ! directive
    complex :: Z, Root, Multiplier
    integer :: M, N, Loop
    real :: X, Y, Phase_Increment
! start program B03
    write (unit = *, fmt = *) " Please enter real and imaginary parts. "
    read (unit = *, fmt = *) X, Y
    Z = cmplx( X, Y )
    write (unit = *, fmt = *) " Please enter numerator and denominator of exponent. "
    read (unit = *, fmt = *) M, N
    Root = Z ** (real( M ) / real( N ) )
    Phase_Increment = 2.0 * atan2( 0.0, -1.0 ) / real( N )  ! 2 * Pi / N
    Multiplier = cmplx( cos( Phase_Increment ), sin( Phase_Increment ) )
    do Loop = 0, N - 1
      write (unit = *, fmt = *) Loop, "  ", Root
      Root = Root * Multiplier
    end do
    stop
  end program B03
