Created
November 3, 2013 09:31
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/*********************************************************** | |
* 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); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
can we do it with recursion