10. Write a program to find the sum of following series 1-X1/1!+X2/2!- ............Xn/n!.
SOURCE CODE:
#include <stdio.h>
#include<math.h>
int fac(int n)
{ if(n==0 || n==1)
return 1;
else return n*fac(n-1);
}
int main()
{ int i,n,x;
float sum=1,c;
printf("enter the value of x and n\n");
scanf("%d %d",&x,&n);
for(i=1;i<=n;i++)
{ c=(pow(-x,i)/fac(i));
sum+=c;
}
printf("value of given series is %f",sum);
return 0;
}
Comments
Post a Comment