A C++ program with function seqsum( ) that has two arguments, double x and int n. The program should be able to find the sum of following series :
1 + x/2! + x2/4! + x3/6! + x4/8! + ...... + xn/(2n)!
1 + x/2! + x2/4! + x3/6! + x4/8! + ...... + xn/(2n)!
#include#include double seqsum(double x, int n) { double sum=1, num=1, div=2, fact=1, term; for(int i=2;i<=n;i++) { num=num*n; fact=fact*(div)*(div-1); term=(num/fact); div=div+2; sum=sum+term; } return sum; } void main() { clrscr(); int x, n; double sum = 0; cout << "Enter the value of x : "; cin >> x; cout << "Enter the value of n : "; cin >> n; sum = seqsum(x, n); cout << "The value of the series : " << sum; }
Source: www.LearnCandCpp.com
No comments:
Post a Comment