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

Need program in C The following set of problems is good instances where recursio

ID: 675059 • Letter: N

Question

Need program in C

The following set of problems is good instances where recursion is advisable. Write code to solve each problem using a recursive function. You can include your recursive function within the same file as your main function. NOTE: Since we are calculating with factorials and are concerned about precision, make sure to use the correct data type. Save the programs for each problem separately in one folder. Zip up the folder and turn it in on Blackboard/Learn under the EC Recursion Ch4 assignment. This assignment is worth a possible total of 2 extra credit points on Midterm 2. Here is the breakdown of where all those points are: 1 point for all the code of problems 1 - 3 0.5 points for answering all the questions for problems 1 - 3 0.5 points for adding error checking to each exercise which requires user input for an added 0.5 points extra credit The cosine of an angle x can be estimated using the following infinite series: cos x = 1- x^2/2!+x^4/4!- x^6/6!+x^8/8!- x^10/10!+... Write a program that reads an angle x (in radians) from the keyboard. Then, in a function, compute the cosine of the angle using the first 5 terms of this series. Print the value computed along with the value of the cosine computed using the C library function. How different are these two answers? The sine of an angle x can be estimated using the following infinite series: sin x = x- x^3/3!+x^5/5!- x^7/7!+x^9/9!- x^11/11!+... Write a program that reads an angle x (in radians) from the keyboard. Then, in a function, compute the sine of the angle using the first 5 terms of this series.

Explanation / Answer

I have code for three programs you can find the below answers for cas x, sin x, e^x series below:

#include<stdio.h>
#include<math.h>

void main()
{
    int n,x1,i,j;
    float x,sign,cosx,fact;

    printf("Enter the number of the terms in aseries ");
    scanf("%d",&n);

   printf("Enter the value of x(in degrees) ");
   scanf("%f",&x);

   x1=x;

   x=x*(3.142/180.0); /* Degrees to radians*/

   cosx=1;

   sign=-1;

   for(i=2;i<=n;i=i+2)
    {
       fact=1;

       for(j=1;j<=i;j++)
       {
           fact=fact*j;
           }

       cosx=cosx+(pow(x,i)/fact)*sign;
             sign=sign*(-1);
   }

   printf("Sum of the cosine series                    = %7.2f ",cosx);
   printf("The value of cos(%d) using library function = %f ",x1,cos(x));

}

Program for sin x series is below:

#include <stdio.h>
#include <math.h>
#include <stdlib.h>

void main()
{
    int n, x1;

    float accuracy, term, denominator, x, sinx, sinval;
    printf("Enter the value of x (in degrees) ");
    scanf("%f", &x);
    x1 = x;

    x = x * (3.142 / 180.0);
    sinval = sin(x);
    printf("Enter the accuracy for the result ");
    scanf("%f", &accuracy);
    term = x;
    sinx = term;
    n = 1;
    do
    {
        denominator = 2 * n * (2 * n + 1);
        term = -term * x * x / denominator;
        sinx = sinx + term;
        n = n + 1;

    } while (accuracy <= fabs(sinval - sinx));

    printf("Sum of the sine series = %f ", sinx);
    printf("Using Library function sin(%d) = %f ", x1, sin(x));

}

Program for e^x series is below:

#include <stdio.h>

float exponential(int n, float x)
{
    float sum = 1.0f;

    for (int i = n - 1; i > 0; --i )
        sum = 1 + x * sum / i;

    return sum;
}
int main()
{
    int n = 10;
    float x = 1.0f;
    printf("e^x = %f", exponential(n, x));
    return 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