81 Zain Jo 46 11 30 Pm Not Secure Cpe Pc Ju Edu Jo In This Task You Are Required To Write A Code Which Takes As An Inp 1 (54.93 KiB) Viewed 26 times
81 Zain Jo 46 11 30 Pm Not Secure Cpe Pc Ju Edu Jo In This Task You Are Required To Write A Code Which Takes As An Inp 2 (27.97 KiB) Viewed 26 times
81% Zain JO 46 11:30 PM Not Secure-cpe-pc.ju.edu.jo In this task, you are required to write a code which takes as an input an angle [0°, 90°) in radians and returns the approximate value of the cosine of this angle. The code will also take as an input the number of terms to be used to approximate the result. We will use the Maclaurin series of cos(x) to approximate the result. The series is given by: cos(x) -1"x2 = Σ=0 (2n!). but for practical reasons, we will not use infinite terms but k terms where kis input by the user: -1"x2 cos(x) = x = 0 (2n!) So, for example, to calculate the cosine for 60° (1.04667 radians) using five terms, the approximation will be: 1 1.04667 1.04667 1.046676 6! + 1.046678 8! = 0.5004 • The program should at most handle 15 terms (to avoid overflows due to factorial), otherwise the program outputs Invalid • There should be at least three terms used in the approximation, otherwise the program outputs Invalid • If the number of terms is negative, the programs corrects it automatically to positive. • If the angle is out of range, the program outputs Invalid
...Zain JO 4G @ 81% 11:30 PM Not Secure-cpe-pc.ju.edu.jo VO Program Input: • A single line that takes in any angle (in radians) • A single line that takes in the number of terms to use in the approximation Program Output: • A single line that outputs the approximate value of the cosine Sample Testcase 0: Input: 1.04667 5 Output: 0.5004572 Sample Testcase 1:
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!