[Helpful tip for evaluating S(n): The math.h header file contains all kinds of useful math functions and utilities that you can use in this code. For example, pow(x,y) =xy, and M_PI = 3.141... Note: for M_PI in Visual C++, we need to include the line #define _USE_MATH_DEFINES before #include < math.h >]
[Another helpful tip: as you code, check each step by running test cases. For math, you can compare test cases against the output of other programs, such as Mathematica or the Wolfram Alpha website, or Google, Maple, Matlab, Octave, etc. ]