Write a program to compute cos(x) for a given real number x (in radians, 0≤x≤2π) using the Taylor series:
To ensure sufficient accuracy, use double precision floating-point arithmetic and sum the series up to n = 15 (i.e., include the terms for n=0,1,…,15).
For example, please perform this calculation
Information about factorial function:
(2n)!=1×2×3×⋯×(2n)
Notes:
Do not call a library cosine function to compute the answer; use the series definition.
For efficiency and numerical stability, update powers and factorials iteratively rather than recomputing them from scratch each term.
Given real number x (in radians, 0≤x≤2π)
Output: Print the result rounded to exactly 6 digits after the decimal point.