Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
C++ program to find the sum of the series 1/1! + 2/2! + 3/3! + 4/4! +…….+ n/n!
In this tutorial, we will be discussing a program to find the sum of the given series 1/1! + 2/2! + 3/3! + 4/4! +…….+ n/n!.
For this, we will be given with the value of n and our task is to add up every term starting from the first one to find the sum of the given series.
Example
#include <iostream>
using namespace std;
//calculating the sum of the series
double calc_sum(int n) {
int i;
double sum = 0, fact=1;
for (i = 1; i <= n; i++)
fact = fact * i;
sum += i/fact;
return sum;
}
int main() {
int n = 6;
double res = calc_sum(n);
cout << res << endl;
return 0;
}
Output
0.00972222
Advertisements