The usual technique for obtaining the spectrum of a signal to use a Fourier transform, most often the FFT. There is one example program at
this page[
^].
By the way, you might prefer to include math.h with the macro _USE_MATH_DEFINES defined. That file has definitions of most common mathematical constants like pi, e, etc. The value of pi is defined in the constant M_PI.