C++ programme to find the sum of the sequence



#include<iostream.h>
#include<conio.h>
#include<math.h>
void sum(int x,int n)
{
               double sum=0,s=0;
               int k=1;
               long fac=1;
               for(int i=1;i<=n-1;i++)
               {
                              for(int j=(2*k);j>=1;j--)
                              {
                                             fac*=j;
                              }
                              sum+=(pow(x,i)/fac);
               }
               s=1+sum;
               cout<<"\nThe sum is:\n";
               cout<<s;
}
void main()
{
               clrscr();
               int x,n;
               cout<<"\nEnter the limiting value\n";
               cin>>n;
               cout<<"\nEnter the value \n";
               cin>>x;
               sum(x,n);
getch();
}

OUTPUT:


Enter the limiting value                                                        
5                                                                              
                                                                               
Enter the value                                                                 
3                                                                              
                                                                               
The sum is:                                                                     
13.1875

No comments:

Post a Comment