Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

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 in
radians, 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!

Explanation / Answer

#include #include #define PI 4*atan(1.0) main() { double x_deg, x, Y, y1, y2, n_fact; int ask1, ask2, n_term, k, i; do { printf(" Enter x_deg: "); scanf("%lf", &x_deg); x = x_deg * (PI/180.); Y = pow(sin(x), 2); printf("True value of sin^2(x) = %g ", Y); printf("n_term approximation of sin^2(x) "); do { printf("Enter number of terms: "); scanf("%d", &n_term); printf("%d term approximation ", n_term); y1 = 1.0; for(k=n_term;k>0;k--) { n_fact = 1.0; for(i=(2*k)+1;i>0;i--) { n_fact *= i; } y1 += (pow(-1,k)/(n_fact+1))*(pow(x,(2*k)+1)); y2 = pow(y1, 2); } printf("sin^2(x) = %g ", y2); printf("Relative Error = %g percent ", 100*(y2-Y)/Y); printf("Do you want a new n_term: y=1 or n=0 "); scanf("%d", &ask2); } while(ask2!=0); printf("Do you want a new x_deg: y=1 or n=0 "); scanf("%d", &ask1); } while(ask1!=0); }
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote