cos(x) from Its Series, With and Without the Library
MediumRead a real number x in radians and an integer N, sum the first N terms of the series cos x = 1 - x^2/2! + x^4/4! - x^6/6! + ..., and print two lines: series cos(x) = 0.540302 with the sum, and library cos(x) = 0.540302 with the value from cos in <math.h>, both to six decimal places. Build each term from the previous one, term = -term * x * x / ((2k + 1)(2k + 2)) for k from 0, rather than computing powers and factorials. N must be between 1 and 100; otherwise print N must be between 1 and 100 and return 1. If x and N cannot be read, print invalid input and return 1.
Success Criteria
Your code must pass 7 test case(s) to complete this exercise. 3 hint(s) are available if you need help.
How did you find this exercise?
Your rating helps us improve the content.
Sign in to track your progress
You can work on exercises as a guest, but sign in to track your progress and save your submissions.