Write a C program, called cos approx.c, that computes the approximate value of cos(x) according to its Taylor series expansion: See image.
This series produces the exact value of cos(x) for any real number x, but contains an infinite number of terms. Obviously, a computer program can compute only a finite number of terms. Thus, you will have to truncate the infinite series in (1). Your program should be able to do so in two different ways.
Fixed number of terms: Implementthefunctioncos N(double x, int N)thatacceptsas pa- rameters a real number x and an integer N (you can assume that N will be always positive). The function cos N should return the sum of the first N terms in (1), as a double.
Fixed precision: Implement the function cos delta(double x, double delta) that ac- cepts as parameters a real number x and another real number δ (you can assume that δ will be always positive). The function cos delta should return, as a double, the sum of the first N terms in (1), where N is the smallest positive integer such that See image.
Noticethat thefirst sum in(2) contains N terms, whilethesecond sumcontains N −1 terms. It is possible for the second sum in (2) to be empty — this happens when N = 1. You should assume that an empty sum evaluates to zero.
Your program should read its input from a file called cos input.dat. The first line in this file is apositiveintegerm (you can assumethat m <= 64). Thefirstlineisfollowedby m otherlines; each such line constitutes a test case. Every test-case line contains three numbers separated by whitespace. The first number is either 1 or 2, indicating whether you should use cos N or cos delta. The second number is the value of x for which you should compute cos(x). The third number y is either the re- quired precision δ (if the first number is 2) or the required number of terms N (if the first number is 1). In the former case, y will be a floating-point number while in the latter case, it will be an integer. In both cases, you can assume that y is positive. Here is a sample cos input.dat file:
5
1 -1.00 6
2 1 0.00001
1 1.5 2
2 2 0.09
2 2 1.1
The program should write its output to the file cos output.dat. The output file should consist of m lines, one per test case. For each test case, the program should print the test-case number followed by cos(x.xxx) = y.yyyyyyyyyyyy. In the above, the argument of cos(·) should beprinted with 3 digits of precision, while its (approximate) value should be printed with 12 digits of precision. For example, here is the file cos output.dat that results upon processing the file cos input.dat above:
Case 1: cos(-1.000) = 0.540302303792
Case 2: cos(1.000) = 0.540302303792
Case 3: cos(1.500) = -0.125000000000
Case 4: cos(2.000) = -0.422222222222
Case 5: cos(2.000) = 1.000000000000