The purpose of this task is to explore working with   complex numbers.



Task

Given   n,   find the   nth   roots of unity.




 
PROGRAM UNITY_ROOTS
 
!
! for rosettacode.org
!
 
BEGIN
   PRINT(CHR$(12);) !CLS
   N=5                                       ! this can be changed for any desired n
   ANGLE=0                                   ! start at ANGLE 0
   REPEAT
     REAL=COS(ANGLE)                         ! real axis is the x axis
     IF (ABS(REAL)<10^-5) THEN REAL=0 END IF ! get rid of annoying sci notation
     IMAG=SIN(ANGLE)                         ! imaginary axis is the y axis
     IF (ABS(IMAG)<10^-5) THEN IMAG=0 END IF ! get rid of annoying sci notation
     PRINT(REAL;"+";IMAG;"i")                ! answer on every line
     ANGLE+=(2*π)/N
                                             ! all the way around the circle at even intervals
   UNTIL ANGLE>=2*π
END PROGRAM
 