This is a simple C++ program which will show how to find the sum of series which are exponential in nature. Given below is one of the sample program
#include "iostream.h" #include "math.h" #include "conio.h" // The function is double SumSeries(double x, int m) { double s = 1/x; float xpower, factVal, fact; int i, j; for(i=0;i<=m;i++) { xpower = 1; for (j=2; j<=i; j++) xpower = xpower * x; factVal = i + 1; fact = 1; for (j=1; j<=factVal; j++) fact = fact * j; if ((i % 2) == 0) s = s - (fact/xpower); else s = s + (fact/xpower); } return(s); } void main() { clrscr(); int m; double sum = 0; double x; cout << "Enter the value of x : "; cin >> x; cout << "Enter the value of m : "; cin >> n; sum = SumSeries(x, m); cout << "The sum of series is : " << sum; } Source: www.LearnCandCpp.comIf you have any query regarding the programming structure or understanding in any concept, you may post it below as a response.
No comments:
Post a Comment