'c program for finding sum of series
the given problem statement is Write a C program to calculate the following Sum: Sum=1-x2/2! +x4/4!-x6/6!+x8/8!-x10/10! to sove this i have written the following code
#include<stdio.h>
#include<math.h>
long fact(int);
void main()
{
int n,x,i;
float s=0;
printf("enter the limit\n");
scanf("%d",&x);
for(i=0,n=0;i<10;i=i+2,n++)
s=s+(pow(1,-n)*pow(x,i))/(fact(i));
printf("the sum of the series is %f\n",s);
}
long fact(int x)
{
if(x==0)
return 1;
else
return fact(x*fact(x-1));
}
but i am not getting any answer the ouput screen shows
enter the limit
5
but it does not give sum upto 5 terms is a there any other way to solve the problem statement
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
