Radical Developers welcomes all the visitors to be a member of the team. Come join us. Its all about open-source concept. All Programs are written and tested in MacOS X, Unix, Linux and may not match with the outputs of Turbo C++ in Windows

Sunday, January 9, 2011

1+x+(x2/2!)+(x3/3!)+………………………………………+(x^n/n!) Write a program to show the sum of he series when x & n is input through the keyboard.


Source Code :

#include<stdio.h>
#include<math.h>
void main()
{
      int x,n,i,j,fact;
      float sum=1;
      clrscr();
      printf("\nEnter the Value of 'x' : ");
      scanf("%d",&x);
      printf("\nEnter the value of 'n' : ");
      scanf("%d",&n);
      for(i=1;i<=n;i++)
      {
            fact=1;
            for(j=1;j<=i;j++)
            {
                  fact*=j;
            }
            sum=sum+(pow(x,i)/fact);
      }
      printf("\nSum of the Series : %5.2f",sum);
      getch();
}

Output :

Enter the Value of ‘x’ : 2

Enter the Value of ‘n’ : 5

Sum of the Series : 7.27

No comments:

Post a Comment