Roots of unity: Difference between revisions
Content deleted Content added
m Moved to Arith cat |
added C |
||
Line 80: | Line 80: | ||
'all the way around the circle at even intervals |
'all the way around the circle at even intervals |
||
LOOP WHILE angle < 2 * PI |
LOOP WHILE angle < 2 * PI |
||
=={{header|C}}== |
|||
#include <ansi_c.h> |
|||
#define PI 3.1415926 |
|||
int main (int argc, char *argv[]) |
|||
{ |
|||
char sign; |
|||
int i, n; |
|||
float rpart, ipart, angle; |
|||
for (n = 2; n <= 10; n++) |
|||
{ |
|||
angle = 0.0; |
|||
printf("%d: ", n); |
|||
for (i = 1; i <= n; i++) |
|||
{ |
|||
rpart = cos(angle); |
|||
ipart = sin(angle); |
|||
if (ipart < 0) |
|||
{ |
|||
sign = '-'; |
|||
} |
|||
else |
|||
{ |
|||
sign = '+'; |
|||
} |
|||
printf("%5.4f%cj%5.4f ", rpart, sign, fabs(ipart)); |
|||
angle = angle + 2.0*PI/(float)n; |
|||
} |
|||
printf("\n"); |
|||
} |
|||
} |
|||
=={{header|C++}}== |
=={{header|C++}}== |