#include #include #include #ifndef J #define J _Imaginary_I #endif int main(); int main() { int i, j; char *ordinals[14] = { "zeroeth", "first", "second", "third", "fourth", "fifth", "sixth", "seventh", "eighth", "nineth", "tenth", "eleventh", "twelveth", "thirteenth" }; for ( i = 1; i <= 13; ++i ) { double const PI = acos( -1.0 ); double complex z, w; printf( "The %s roots of unity:\n", ordinals[i] ); // The principal ith root of unity // - must compile with the -std=c11 option z = CMPLX( cos(2.0*PI/i), sin(2.0*PI/i) ); // If only C99 is available, use this instead: // z = cos(2.0*PI/i) + sin(2.0*PI/i)*J; for ( j = 1; j <= i; ++j ) { w = cpow( z, j ); printf( " %f%+fj\n", crealf(w), cimagf(w) ); } printf( "\n" ); } return 0; }