/*PROGRAM TO PRINT A SERIES AND FIND ITS SUM: x/1! – x^3/3! + x^5/5! -x^7/7! —– n terms*/
#include<conio.h>
#include<iostream.h>
#include<math.h>
class series
{
int i,n,x,a,count,j;
float sum,b;
public:
void process();
};
void series::process()
{
cout<<“Enter the limit of the series: “;
cin>>n;
cout<<“Enter the value of x: “;
cin>>x;
cout<<“Series is:\n\t”;
count=0;
sum=0;
for(i=1;i<=2*n;i=i+2)
{
count++;
a=pow(x,i);
b=1;
for(j=1;j<=i;j++)
b=b*j;
cout<<a<<“/”<<i<<“!”;
if(i<2*n-1)
{
if(count%2==0)
cout<<” + “;
else
cout<<” – “;
}
if(i<2*n)
{
if(count%2==0)
sum=sum-(a/b);
else
sum=sum+(a/b);
}
}
cout<<“\nSum of series is: “<<sum;
}
void main()
{
series s1;
clrscr();
s1.process();
getch();
}