We want to draw the star polygon at N vertices, of step p, inscribed in the trigonometric circle. The summits have for coordinates: \((x_k,y_k)=(\cos{\frac{2\pi kp}{N}},\sin{\frac{2\pi kp}{N}}), k=0 \cdots N\)

We fixe N = 25 and p = 7. Write a program that displays the coordinates of these vertices in the form:
1.000000 0.000000
-0.187381 0.982287
-0.929776 -0.368125
....
1.000000 0.000000


Difficulty level
This exercise is mostly suitable for students
#include <stdio.h>
#include <math.h>
#include <conio.h>
#define N 25
#define P 7
#define M_PI 3.14159265358979323846
void main()
{
	int k;
	double a, x, y;
	for(k=0; k<=N; k++)
	{
		a=(2.*M_PI*P*k)/N;
		x=cos(a);
		y=sin(a);
		printf("%f %f\n", x, y);
	}
	getch();
}

Back to the list of exercises
Looking for a more challenging exercise, try this one !!
UVA 1112 - Mice and Maze