‘C’ program to accept real number x and integer n and calculate the sum of first n terms of the series x+ x/3!+ x/5!+ x/7!+…

C File =>


/* Write a ‘C’ program to accept real number x and integer n and calculate 
the sum of first n terms of the series
x+ x/3!+ x/5!+ x/7!+… */

#include<stdio.h>
int main() 
{
      int x,n,i;
      float sum=0;
 
      printf("\n Enter value of x : ");
      scanf("%d",&x);
      printf("\n Enter value of n : ");
      scanf("%d",&n);
       printf("\n\n Sum of series x+x/3!+x/5!...\n");
 
  // defining function to compute factorial
      int fact(int n)
     {
          if(n==1)
              return 1;
         else
              return (n*fact(n-1));
      }
 
     // computing sum of series
      for(i=1;i<=n;i=i+3)
          sum=sum+x/fact(i);
 
      printf("\n %f",sum);
 
      return 0;
}

Comments

Popular posts from this blog

Write a program to allocate memory dynamically for n integers. Accept the elements and calculate their sum and average

C program to accept names of n cities and search for city named “Pune”.