在线编译器 C

#include <stdio.h> float cosinus(float x){ float x2=x*x; return 1-x2/2+x2*x2/24-x2*x2*x2/720; } int main(){ float degree; scanf("%f",&degree); float radian =degree*3.14159265/180; printf("%.3f\n",cosinus(radian)); return 0; }
This code approximates the cosine of an angle using a Taylor series expansion up to the x^6 term. It converts degrees to radians and prints the result with three decimal places.

- The Taylor series approximation uses only a few terms, but the factorial denominators (2, 24, 720) are hardcoded. Check if the factorial values are correct for the terms you intend to include.
- The series expansion for cosine is an alternating series. Verify the signs of each term: the pattern should be +, -, +, -, ... starting with the first term (1).