Thursday, 30 November 2017

series

Q : Write a program to compute the following series:

x + x3 / 3! + x5/ 5! + …

To a given accuracy for x from 00 to 1800 in the steps of 100, use a inbuilt function FACT(n) to compute the factorial.

Solution : 

#include<stdio.h>
#include<conio.h>
int fact(int);
void main()
{
     int x,step,y,i;

     long double  f;
     clrscr();
     printf("Enter no of step for series>> ");
     scanf("%d",&step);
     printf("Enter value of X>> ");
     scanf("%d",&x);
     for(f=0,y=3,i=1;i<=step;i++)
     {
          f+=x*y/(float)fact(y);
          y+=2;
     }
     printf("X value after %d step is %f",step,f);
     getch();
}
int fact(int n)
{
     int m;
     for(m=1;n>0;n--)
          m=m*n;
     return(m);

}

No comments:

Post a Comment