Code for Taylor series method in C

C code to implement  Taylor series method  .  Compiled in DEV C++

website_caption1

#include<stdio.h>
#include<conio.h>
#include<math.h>
long int factorial(int n);

int main()
{
 int x,i;
 float s,r;
 char c;

printf("You have this series:-1+x/1! + x^2/2! + x^3/3! + x^4/4!..x^x/x!");
 printf("To which term you want its sum of ?  ");
 scanf("%d",&x);
 s=0;
 for (i=1;i<=x;i++)
  {   s=s+((float)pow(x,i)/(float)factorial(i)); 
}
 printf("The sum of %d terms is %f",x,1+s);

 fflush(stdin);
      getch();
}

long int factorial(int n)
 {
  if (n<=1)
 return(1);
  else
 n=n*factorial(n-1);
 return(n);
 }

website_caption1

You might be also interested in :

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s