+ 1
write a c++ program to compute the cosine series
cos(x) = 1-x^2 / 2! + x^4 / 4! - x^6 / 6!+...x^n / n!
2 ответов
+ 7
int factorial( int n )
{
int fact=1;
for(int I=1;I<=n;I++)
fact*=I;
return fact;
}
int pow(int a,int b)
{
int power=1;
for(int I=1;I<=b;i++)
power*=a;
return power;
}
float cosine(int x,int n)
{
int sign=1;
float cos=0.0;
for(int I=0; I<=n;I+=2,sign*=-1)
cos+=(pow(x,I))/factorial(I)*sign;
return cos;
}
//change data types of you require
//sorry for semicolons missing and undeclared variables if any 😑😑😑
+ 4
Thanks a lot!