Find and display the values of both sides of the following mathematical series expression and
an absolute difference of both sides. User can input either of angles in degree 90, 60, 30 etc.
sin(x) = x −
x
3
3!
+
x
5
5!
−
x
7
7!
+
x
9
9!
#include <iostream>
#include <cmath>
using namespace std;
long getFactorial(int n) {
int c;
long factr = 1;
for (int c = 1; c <= n; c++) {
factr = factr * c;
}
return factr;
}
int main()
{
double x =90;
double res;
res = sin(x);
cout<<"\nResult 1: "<<res;
double a, b, c, d;
a=(pow(x,3)/getFactorial(3));
b=(pow(x,5)/getFactorial(5));
c=(pow(x,7)/getFactorial(7));
d=(pow(x,9)/getFactorial(9));
double res2=x-a+b-c+d;
cout<<"\nResult 2: "<<res2;
return 0;
}
Comments
Leave a comment