write a program to find the sum of following series:- 1+x^2/3!+x^3/4!+x^4/5!+............+x^n/(n+1)!
1
Expert's answer
2013-07-16T11:36:16-0400
#include <iostream> #include <conio.h> #include <math.h> using namespace std; //find factorial double factorial(long n){ if (n < 1) return 0; double product = 1; for (int i = 1; i <= n; i++) product *= i; return product;//return result } //main function int main() { double x;//variable for x int sum=1;//variable for sum cout<<"Enter x: ";//enter x cin>>x;//read x for(int i=2;i<1000;i++){ sum+=pow(x,i)/(factorial(i+2));//find sum } //show result cout<<"Sum = "<<sum; getch();//delay return 0; }
Comments
Leave a comment