Subscribe for more such posts..

Dear Reader...
I hope u are like my posts. If so then please don't forget to like , share and follow my blog for more such posts ,also feel free to write suggestions in the comment box given over here.

Thank you...

Search This Blog

C Program to find the sum of following series 1 - X1/1! + X2/2! - ………… Xn/n!


#include <math.h> int fact(int x) { if(x ==1) return 1 ; else return x * fact(x - 1); } double series(double x , int n) { double sum = 1 ; for(int i = 1 ; i <= n ; i++) { if(i%2 != 0) { sum = sum - (pow(x,i)/fact(i)); } else { sum = sum + (pow(x , i )/fact(i)); } } return sum ; } int main() { double x ; int n; printf("Enter the value of x : "); scanf("%lf" , &x ); printf("Enter the value of n : "); scanf("%d" , &n); printf("Sum of the given series is : %.4lf\n" , series(x,n)); }

No comments:

Post a Comment