Pages

Saturday, June 16, 2012

write a c program to find sum of following series? sum=1-X2/2!+.............

#include<stdio.h>
#include<conio.h>
#include<math.h>
void main()
{
   int x,i,j,sign=-1;
   long int fact=1;
   double s=0.00;
   clrscr();
   printf("enter the value of x:\t");
   scanf("%d",&x);
   for(i=0;i<=10;i=i+2)
   {
   fact=1;
   for(j=1;j<=i;j++)
   {
   fact=fact*j;
   }
   s=s+((-1*sign)*pow(x,i))/fact;
   if(sign==-1)
       sign=1;
       else
         sign=-1;
         }
printf("\n the result is:%1f",s);
getch();
}

No comments:

Post a Comment