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

Write a program that uses a recursive function, and the following algorithm, to

ID: 3686022 • Letter: W

Question

Write a program that uses a recursive function, and the following algorithm, to approximate the sin function. The result is output to the screen, as part of the main function To do this, create a recursive function to calculate the sum of series of the sin function. namely sin(x) = sigma^x_n = 0 (-1)^n/(2n +1)! x^2n + 1. Note that this sum involves an infinite series. Thus, a maximum n = 5 iterations is to be used. Moreover, this sum involves a factorial, specifically (2n + 1)! This factorial is to be calculated Iteratively Your submission should include a screenshot of the execution of the program using each of the angles (in radians) -pie/6, 2pie/3 and 3pie/4.

Explanation / Answer

Here is the code for you:

#include <iostream>
#include <iomanip>
#include <cmath>
#define PI 3.14159265359
using namespace std;

double factorial(int n)
{
int fact = 1;
for(int i = 1; i <= n; i++)
fact *= i;
cout<<n<<" "<<fact<<endl;
return fact;
}
double sineCalc(int x, int count)
{
double result = 0;
double term;
if(count == 0)
return x;
//term = pow(x, 2*count   - 1)/factorial(2*count - 1);
//if(count % 2 != 0)
// term *= -1;
return pow(-1, n)*pow(x, 2*count   - 1)/factorial(2*count - 1) + sineCalc(x, count - 1);
}
int main()
{
int radians;
cout<<"Enter the number of radians: ";
cin>>radians;
cout<<"Sin("<<radians<<"): "<<sin(radians)<<endl;
double sineValue = sineCalc(radians, 5);
cout<<"Sine approximation: "<<fixed<<setprecision(6)<<sineValue<<endl;
}

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