The sin of and angle may be obtained from the series: sin x = x-x3/3! + x5/5! -
ID: 3625330 • Letter: T
Question
The sin of and angle may be obtained from the series:sin x = x-x3/3! + x5/5! - x7/7! + x9/9! - ...
Write a program to compute and output the sin of an angle (in degrees) using the first 5 terms. Since the above formula uses radian degree measure, the original angle, input degrees, must be converted to radian measure. The procedure you see must be efficient. It should make use of both the previous calculation for numerator and denominator. How does your answer compare to a calculator's or table's answer?
Explanation / Answer
please rate - thanks
sorry about that!!
# include <iostream>
using namespace std;
double calculate(double);
int main ()
{double x;
cout<<"Enter a value for x: ";
cin>>x;
cout<<"sin("<<x<<")="<<calculate(x)<<endl;
system("pause");
return 0;
}
double calculate(double x)
{double sinx,term,pi=3.1415,facti=1,xx,powx;
int i=3,flip=-1,terms=1;
sinx=x*pi/180;
xx=sinx;
powx=xx;
do
{facti=facti*i*(i-1);
xx=xx*powx*powx;
term=xx/facti;
sinx+=(term*flip);
flip=0-flip; //this changes between -1 and +1
//when it's -1 you subtract
//when it's +1 you add
i+=2;
}while(i<=9);
return sinx;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.