Skip to content

Instantly share code, notes, and snippets.

@snadahalli
Created November 3, 2013 09:31
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save snadahalli/7288039 to your computer and use it in GitHub Desktop.
Save snadahalli/7288039 to your computer and use it in GitHub Desktop.
C Program to evaluate the following series. f(x)=x-x3/3! + x5/5!-x7/7!.....into given numbers of terms.
/***********************************************************
* You can use all the programs on www.c-program-example.com
* for personal and learning purposes. For permissions to use the
* programs for commercial purposes,
* contact info@c-program-example.com
* To find more C programs, do visit www.c-program-example.com
* and browse!
*
* Happy Coding
***********************************************************/
#include<stdio.h>
int main()
{
long int x,i,j,k,n,sq,cnt;
double fact,sum=0;
printf("\n ENTER THE VALUE OF N: ");
scanf("%ld",&n);
printf("\n ENTER THE VALUE OF X: ");
scanf("%ld",&x);
for(i=1,cnt=1;i<=n;i=i+2,cnt++)
{
for(j=1,sq=1;j<=i;j++)
sq=sq*x;
for(k=1,fact=1;k<=i;k++)
fact=fact*k;
if(cnt%2==1)
sum=sum+(sq/fact);
else
sum=sum-(sq/fact);
printf("\n THE SUM OF THIS SERIES IS %7.2lf\n",sum);
}
}
@arjun-695
Copy link

can we do it with recursion

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment