
- C++ Basics
- C++ Home
- C++ Overview
- C++ Environment Setup
- C++ Basic Syntax
- C++ Comments
- C++ Data Types
- C++ Variable Types
- C++ Variable Scope
- C++ Constants/Literals
- C++ Modifier Types
- C++ Storage Classes
- C++ Operators
- C++ Loop Types
- C++ Decision Making
- C++ Functions
- C++ Numbers
- C++ Arrays
- C++ Strings
- C++ Pointers
- C++ References
- C++ Date & Time
- C++ Basic Input/Output
- C++ Data Structures
- C++ Object Oriented
- C++ Classes & Objects
- C++ Inheritance
- C++ Overloading
- C++ Polymorphism
- C++ Abstraction
- C++ Encapsulation
- C++ Interfaces
Sum of the Series 1/(1*2) + 1/(2*3) + 1/(3*4) + 1/(4*5) + ... in C++n
In this problem, we are given a number n which is the nth term of the series 1/(1*2) + 1/(2*3) +…+ 1/(n*(n+1)). Our task is to create a program to find the sum of the series.
Let’s take an example to understand the problem,
Input
n = 3
Output
0.75
Explanation − sum = 1/(1*2) + 1/(2*3) + 1/(3*4) = ½ + ⅙+ 1/12 = (6+2+1)/12 = 9/12 = ¾ = 0.75
A simple solution to the problem is using the loop. And commuting value for each element of the series. Then add them to the sum value.
Algorithm
Initialize sum = 0 Step 1: Iterate from i = 1 to n. And follow : Step 1.1: Update sum, sum += 1/ ( i*(i+1) ) Step 2: Print sum.
Example
Program to illustrate the working of our solution,
#include <iostream> using namespace std; double calcSeriesSum(int n) { double sum = 0.0; for (int i = 1; i <= n; i++) sum += ((double)1/(i*(i+1))); return sum; } int main() { int n = 5; cout<<"Sum of the series 1/(1*2) + 1/(2*3) + 1/(3*4) + 1/(4*5) + ... is "<<calcSeriesSum(n); return 0; }
Output
Sum of the series 1/(1*2) + 1/(2*3) + 1/(3*4) + 1/(4*5) + ... is 0.833333
This solution is not much effective as it uses loops.
An effective approach to solve the problem is using the general formula for the sum of series.
The series is 1/(1*2) + 1/(2*3) + 1/(3*4) + 1/(4*5) + … n-th terms is 1/n(n+1). an = 1/n(n+1) an = ((n+1) - n) /n(n+1) an = (n+1)/n(n+1) - n/ n(n+1) an = 1/n - 1/(n+1) sum of the series is sum = 1/(1*2) + 1/(2*3) + 1/(3*4) + 1/(4*5) + … Changing each term as in above formula, sum = 1/1 - ½ + ½ - ⅓ + ⅓ - ¼ + ¼ -⅕ + …. 1/n - 1/(n+1) sum = 1 - 1/(n+1) sum = (n+1 -1) / (n+1) = n/(n+1)
Example
Program to illustrate the working of our solution,
#include <iostream> using namespace std; double calcSeriesSum(int n) { return ((double)n/ (n+1)); } int main() { int n = 5; cout<<"Sum of the series 1/(1*2) + 1/(2*3) + 1/(3*4) + 1/(4*5) + ... is "<<calcSeriesSum(n); return 0; }
Output
Sum of the series 1/(1*2) + 1/(2*3) + 1/(3*4) + 1/(4*5) + ... is 0.833333
- Related Articles
- 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) + (3*3) + (4*4) + (5*5) + … + (n*n)
- Observe the following pattern$1=\frac{1}{2}\{1 \times(1+1)\}$$1+2=\frac{1}{2}\{2 \times(2+1)\}$$1+2+3=\frac{1}{2}\{3 \times(3+1)\}$$1+2+3+4=\frac{1}{2}\{4 \times(4+1)\}$and find the values of each of the following:(i) $1 + 2 + 3 + 4 + 5 +….. + 50$(ii)$31 + 32 +… + 50$
- Program to find sum of series 1 + 1/2 + 1/3 + 1/4 + .. + 1/n in C++
- Sum of the series 1 / 1 + (1 + 2) / (1 * 2) + (1 + 2 + 3) / (1 * 2 * 3) + … + upto n terms in C++
- Simplify:\( 5 \frac{1}{4} \p 2 \frac{1}{3}-4 \frac{2}{3} \p 5 \frac{1}{3} \times 3 \frac{1}{2} \)
- Following data gives the number of children in 41 families:$1, 2, 6, 5, 1, 5, 1, 3, 2, 6, 2, 3, 4, 2, 0, 0, 4, 4, 3, 2, 2, 0, 0, 1, 2, 2, 4, 3, 2, 1, 0, 5, 1, 2, 4, 3, 4, 1, 6, 2, 2.$Represent it in the form of a frequency distribution.
- C++ program to find the sum of the series 1/1! + 2/2! + 3/3! + 4/4! +…….+ n/n!
- Sum of series 1^2 + 3^2 + 5^2 + . . . + (2*n – 1)^2
- Python 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 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!
- Simplify:(i) \( \left\{4^{-1} \times 3^{-1}\right\}^{2} \)(ii) \( \left\{5^{-1}\div6^{-1}\right\}^{3} \)(iii) \( \left(2^{-1}+3^{-1}\right)^{-1} \)(iv) \( \left\{3^{-1} \times 4^{-1}\right\}^{-1} \times 5^{-1} \)(v) \( \left(4^{-1}-5^{-1}\right)^{-1}\div3^{-1} \)
- Observe the following pattern\( 1^{2}=\frac{1}{6}[1 \times(1+1) \times(2 \times 1)+1)] \)\( 1^{2}+2^{2}=\frac{1}{6}[2 \times(2+1) \times(2 \times 2)+1)] \)\( 1^{2}+2^{2}+3^{2}=\frac{1}{6}[3 \times(3+1) \times(2 \times 3)+1)] \)\( 1^{2}+2^{2}+3^{2}+4^{2}=\frac{1}{6}[4 \times(4+1) \times(2 \times 4)+1)] \)and find the values of each of the following:(i) $1^2 + 2^2 + 3^2 + 4^2 +…………… + 10^2$(ii)$5^2 + 6^2 + 7^2 + 8^2 + 9^2 + 10^2 + 11^2 + 12^2$
- Simplify:(i) \( \left(4^{-1} \times 3^{-1}\right)^{2} \)(ii) \( \left(5^{-1}\div6^{-1}\right)^{3} \)(iii) \( \left(2^{-1}+3^{-1}\right)^{-1} \)(iv) \( \left(3^{-1} \times 4^{-1}\right)^{-1} \times 5^{-1} \)

Advertisements