Saturday 24 September 2011

Program for following sum of series

This program is used to find the sum of the exponential series:

1 + x/2! + x2/4! + x3/6! + x4/8! + ....... + xn/(2n)!



// The required function is :
#include 
#include 
double seqsum(double x, int n)
{
double sum=1, num=1, div=2, fact=1, term;
for(int i=2;i<=n;i++)
 {
  num=num*n;
  fact=fact*(div)*(div-1);
  term=(num/fact);
  div=div+2;
  sum=sum+term;
 }
 return sum;
}
void main()
{
 clrscr();
 int x, n;
 double sum = 0;
 cout << "Enter the value of x : ";
 cin >> x;
cout << "Enter the value of n : ";
 cin >> n;
sum = seqsum(x, n);
cout << "The value of the series : " << sum;
}



No comments:

Post a Comment