PROGRAM TO FIND ITS SUM: x/1!+x^2/2!+x^3/3!+ — + n terms

/*PROGRAM TO PRINT A SERIES AND FIND ITS SUM: x/1! + x^2/2! + x^3/3! + — + n terms*/

#include<conio.h>

#include<iostream.h>

#include<math.h>

class series

{

int i,n,x;

float sum,a,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”;

b=1;

for(i=1;i<=n;i++)

{

a=pow(x,i);

b=b*i;

cout<<a<<“/”<<i<<“!”;

if(i<n)

cout<<”  +  “;

sum=sum+(a/b);

}

cout<<“\nSum of series is: “<<sum;

}

void main()

{

series s1;

clrscr();

s1.process();

getch();

}

Leave a Reply

Your email address will not be published. Required fields are marked *