Â
In this, we are going to see a program in which we will find sum of series of elements 1-x^2 / 2!+x^4 / 4!-x^6 / 6!+x^8 / 8!-x^10 /10! as shown in above image in C Programming Language.
/*sum of series of elements
1-x^2 / 2!+x^4 / 4!-x^6 / 6!+x^8 / 8!-x^10 /10!
*/
#include <stdio.h>
#include <math.h>
long facto(int);
void main()
{
double x, sum = 1, flag = 0;
long i;
printf("Enter the value of x: ");
scanf("%lf", &x);
for (i = 2; i <= 10; i++)
{
if (flag == 0)
{
sum = sum - (pow(x, i) / facto(i));
flag = 1;
}
else
{
sum = sum + (pow(x, i) / facto(i));
flag = 0;
}
}
printf("Sum of series of elements = %f\n", sum);
}
long facto(int n)
{
long factorial;
if (n == 1)
{
return 1;
}
else
{
factorial = n * facto(n - 1);
return (factorial);
}
}
#ENJOY CODING
Post a Comment
FOR ANY DOUBTS AND ERRORS FEEL FREE TO ASK. YOUR DOUBTS WILL BE ADDRESSED ASAP