#include<iostream>
using namespace std;
#include<conio.h>
int fact(int);
#include<math.h>
int main()
{ double sum=1;
int x,i=1,n;
cout<<"1+x+(x^2)/2!+............+(x^n)/n!\n\n\n\n";
cout<<"enter the value of x ";
cin>>x;
cout<<"enter th value of n "; cin>>n;
while(i<=n)
{
sum=sum+(pow(x,i)/fact (i));
i++;
}
double val=(double)sum; //typecasting
cout<<"sum is "<<val;
getch();
}
int fact(int j)
{
int fact=1,k=1;
while(k<=j)
{
fact=fact*k;
k++;
}
return fact;
}
No comments:
Post a Comment