y= 1 - x + (x^2/2)- (x^3/6) + (x^4/24)+...+(-1)^n.x^n/n!
to put in my function call..
but i don`t know how to write ..! i`m new with these functions!!
i can`t figure out how to write that form i mentioned upward!!!
with the note that func ( int n ; double x; )
thanks who helps...
and after i`ll post my results for people to discuss...
this is my question:
1. Write a program that includes a function to evaluate the first n terms in the series specified by .
Where n (defined as int) and x (defined as double) are input parameters to that function.
please notice that i can use (-1) for the trick upthere as its (plus, min, plus, min... )series
but i`m demand to use twice ... once to write using (-1)
but the other time .. i have to write the new program with the same series set without the help of (-1)
#include <iostream>
usingnamespace std;
double power(int n, double x)
{
double d =1;
for (int i = 1 ; i<=n ; i++)
d *= x;
return d;
}
double fact(int n)
{
double d =1;
for (int i = 1 ; i<=n ; i++)
d *= n;
return d;
}
double function (int n, double x)
{
double y = 0;
for ( int i=0; i< n ; i++)
{if (i%2 == 0)
y = y + (power(i , x) / fact (i) );
else
y = y - (power(i , x) / fact (i) );
}
return y;
}
int main ()
{
int n ;
double x;
double result;
cout<< "enter integers N & X: \n";
cin>> n >> x;
result =function(n ,x);
cout<< "the result is: " << result<< endl;
return 0;
}
/*
enter integers N & X:
3 5
the result is: 2.25
Press any key to continue
*/
/*
enter integers N & X:
4 2
the result is: -0.296296
Press any key to continue
*/