Scan the angle in degrees x_deg. Express this angle in radians, and then calcula
ID: 3631490 • Letter: S
Question
Scan the angle in degrees x_deg. Express this angle inradians, and then calculate Y=sin(x)+cos(x) by
using the math.h library of functions. Compare the so
calculated value of Y with the approximate value y
obtained by using n_term terms of the Taylor series for
each of
sin(x)=Sum[(-1)^n x^(2n+1)/(2n+1)!] (n goes from 0 to n_term-1)
and
cos(x)=Sum[(-1)^n x^(2n)/(2n)!] (n goes from 0 to n_term-1).
Scan an integer value of n_term. Evaluate (2n)! and (2n+1)! by embedded
for-loop statements. Use two do/while statements to continue
the calculations for different n_term and different x_deg. For
example, use flag=1 to continue calculations for different n_term
within the inner do/while loop, and flag=0 to exit that loop.
Use Flag=1 to continue calculations for different x_deg
within the outer do/while loop, and Flag=0 to exit that loop.
Use %g format for all double values. Use double declaration
when calculating k! (because k! for large k becomes quickly
too big for integer declaration).
.................................................................
Your output should look like this:
Calculation of true and approximate values of sin(x)+cos(x)
Enter x_deg: 30
True value of sin(30)+cos(30) = 1.36603
n_term approximation of sin(30)+cos(30)
Enter number of terms:
2
2 term approximation
sin(30)+cos(30) = 1.3626
Relative Error = 0.251025 percent
Do you want new n_term: y=1 or n=0
1
Enter number of terms:
5
5 term approximation
sin(30)+cos(30) = 1.36603
Relative Error = -3.26636e-08 percent
Do you want new n_term: y=1 or n=0
0
Do you want new x_deg: y=1 or n=0
1
Enter x_deg: 60.5
True value of sin(60.5)+cos(60.5) = 1.36278
n_term approximation of sin(60.5)+cos(60.5)
Enter number of terms:
2
2 term approximation
sin(60.5)+cos(60.5) = 1.30221
Relative Error = 4.4442 percent
Do you want new n_term: y=1 or n=0
1
Enter number of terms:
5
5 term approximation
sin(60.5)+cos(60.5) = 1.36278
Relative Error = -3.78734e-05 percent
Do you want new n_term: y=1 or n=0
0
Do you want new x_deg: y=1 or n=0
0
I am confused on where to start i know you need 2 or 3 for loops and 2 do/while loops but not sure what to do first and how to put it together. Any help would be great!