/* calculation of polynomials poly.c */ #include #include #define N 6 int factorial(int number) { if (number < 1) { return 1; } for (int i = number-1; i > 1; i--) { number *= i; } return number; } int main() { /**** (1) variable declaration ****/ /* set coefficients */ double c[N] = {sin(0)/factorial(0), // evaluates to 0 cos(0)/factorial(1), // evaluates to 1 -sin(0)/factorial(2), // evaluates to 0 -cos(0)/factorial(3), // evaluates to 1/6 sin(0)/factorial(4), // evaluates to 1/24 cos(0)/factorial(5)}; // evaluates to 1/120 double x, y; int i ; /**** (2) processing contents ****/ printf("x values:\n"); for(x = -M_PI; x <= M_PI; x += M_PI/100){ printf("%f, ", x); } printf("\ny values:\n"); for(x = -M_PI; x <= M_PI; x += M_PI/100){ for(y = c[N-1], i = N-2; i >= 0; --i) { y = y * x + c[i]; } printf("%f, ", y); } return 0; return 0; }