img
Question:
Published on: 3 December, 2024

Write a C program to calculate the following sum:

Sum = 1-x^2/2!+x^4/4!-x^6/6!+x^8/8!-x^10/10!
Answer:
#include<stdio.h> 
#include<conio.h> 
#include<math.h> 
void main()
{
   int i,n=10,x; long int fact=1; float sum=1;
   printf(“Enter the x value:); 
   scanf(%d”, &x); 
   for(i=1;i<=n;i++)
   {
       fact=fact*i; if(i%2==0)
       {
           if(i==2||i=10||i==6) 
                sum+= -pow(x,i)/fact; 
           else 
                sum+=pow(x,i)/fact;
       }
   }
   printf(“sum is %f”, sum);
}

Random questions