- Related Questions & Answers
- C++ Program to find the sum of a Series 1/1! + 2/2! + 3/3! + 4/4! + …… n/n!
- Python Program to find the sum of a Series 1/1! + 2/2! + 3/3! + 4/4! +…….+ n/n!
- Java Program to find the sum of a Series 1/1! + 2/2! + 3/3! + 4/4! +…….+ n/n!
- C++ program to find the sum of the series 1/1! + 2/2! + 3/3! + 4/4! +…….+ n/n!
- C++ program to find the sum of the series (1*1) + (2*2) + (3*3) + (4*4) + (5*5) + … + (n*n)
- C++ program to find the sum of the series (1/a + 2/a^2 + 3/a^3 + … + n/a^n)
- Program to find sum of series 1*2*3 + 2*3*4+ 3*4*5 + . . . + n*(n+1)*(n+2) in C++
- Sum of the series 1 + (1+2) + (1+2+3) + (1+2+3+4) + ... + (1+2+3+4+...+n) in C++
- C++ program to find the sum of the series 1 + 1/2^2 + 1/3^3 + …..+ 1/n^n
- Sum of the Series 1/(1*2) + 1/(2*3) + 1/(3*4) + 1/(4*5) + ... in C++\n
- Sum of the series 1 / 1 + (1 + 2) / (1 * 2) + (1 + 2 + 3) / (1 * 2 * 3) + … + upto n terms in C++
- Program to find sum of series 1 + 1/2 + 1/3 + 1/4 + .. + 1/n in C++
- Program to find sum of 1 + x/2! + x^2/3! +…+x^n/(n+1)! in C++
- C++ Programe to find n-th term in series 1 2 2 3 3 3 4
- Program to find sum of series 1 + 2 + 2 + 3 + 3 + 3 + .. + n in C++

- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who

In this problem, we are given two numbers a and n. Our task is to create a *program to find Sum of a Series a^1/1! + a^2/2! + a^3/3! + a^4/4! +…….+
a^n/n! in C++*.

**Problem description** − The problem is to find the sum of the given series using the given values of a and n. The series is a special series in which each term is the multiple of the last term with a/i, i -> 1 to n.

**Let’s take an example to understand the problem**

a = 3, n = 4

15.375

sum of series is

(3^1)/1! + (3^2)/2! + (3^3)/3! + (3^4)/4! = 3 + 9/2 + 27/6 + 81/24 = 15.375

To find the sum of the series, we will use loops to find the ith term of the series and add them to find the sum.

The computation of each element of the series directly has calculation overhead. So, we will use last term to find the next term.

Here, ith term = (i-1)th term * a/i.

Using this we will find terms with less calculations that improves the overall performance of the code.

**Program to illustrate the working of our solution**

#include <iostream> using namespace std; float calcSeriesSum(int a, int n){ float sumVal = 0, term = 1; for(float i = 1; i <= n; i++){ term *= a/i; sumVal += term; } return sumVal; } int main(){ int a = 3, n = 4; cout<<"The sum of the series is "<<calcSeriesSum(a, n); return 0; }

The sum of the series is 15.375

Advertisements