1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45
|
//value of b for any x
#include <iostream>
#include <cmath>
using namespace std;
int main ()
{
long int n ,x,f,k=3,a,b,j ;
float B=0;
cout<<"Enter The Number of Terms = "<<endl;
cin>>n;
cout<<"Enter The Value of x = "<<endl;
cin>>x;
for (int i = 1 ; i<=n ; i++)
{
f=1;
if (k>7) // for the factorial
k=3;
for (j=1;j<=k;j++)
f=f*j;
a=i*(i+1); // for the power of x 2,6,12,20
b=i*i; // for the power of x 1,4,9,16
if ((i-1)%6<3){ // for the sign of the first three terms +, +, +
if (i%2==0){
B=B+sqrt(exp(pow(x,a)))/f;cout<<"one "<<B<<endl;}
else {B=B+sqrt(exp(pow(x,b)))/f;cout<<"two "<<B<<endl;}}
else if ((i-1)%6>=3){ // for the sign of the last three terms -, -, -
if (i%2==0){
B=B-sqrt(exp(pow(x,i*(i+1))))/f;cout<<"three "<<B<<endl;}
else{
B=B-sqrt(exp(pow(x,i*i)))/f;cout<<"four "<<B<<endl;}}
k=k+2;
}
cout<<"The value of B= "<<B<<endl;
return 0 ;
}
|