0
1.2kviews
Write a program in C to implement following summation of series upto n terms.

$1 – x^2 / 2! + x^4 / 4! – x^6 / 6! + x^8 / 8!$


Mumbai university > FE > SEM 2 > Structured Programming Approach

Marks: 10M

Year: Dec 2015

1 Answer
0
1views
#include<stdio.h>
#include<math.h>

int factorial(int m);
void main()
{
    int n,i,sign,x;
    sign=1
    float sum,term;
    term=1
    sum=1;
 printf("Enter the value of x and n: ");
    scanf("%d,%d",&x,&n);
    for(i=2;i<n;i++)
    if(i%2==0)
     {
      sign = sign * (-1);
      term = sign*pow(x,i)/factorial(i);
      sum= sum + term;
     }
    getch();
}
int factorial(int m)
{
    if(m!=1)
     return m*factorial(m-1);
}
Please log in to add an answer.