Found 7197 Articles for C++

Sum of the Series 1/(1*2) + 1/(2*3) + 1/(3*4) + 1/(4*5) + ... in C++

sudhir sharma
Updated on 14-Aug-2020 14:04:06

654 Views

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 = 3Output 0.75Explanation − sum = 1/(1*2) + 1/(2*3) + 1/(3*4) = ½ + ⅙+ 1/12 = (6+2+1)/12 = 9/12 = ¾ = 0.75A 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.AlgorithmInitialize sum = 0 Step 1: Iterate from i = ... Read More

Sum of the series 1, 3, 6, 10… (Triangular Numbers) in C++

sudhir sharma
Updated on 14-Aug-2020 14:00:04

1K+ Views

In this problem, we are given a number n which is given the n of elements of the series 1, 3, 6, 10 … (triangular number). Our task is to create a program to calculate the sum of the series.Let’s brush up about triangular numbers before calculating the sum.Triangular numbers are those numbers that can be represented in the form of a triangle.A triangle is formed in such a way that the first row has one point, second has two, and so on.ExampleLet’s take an example to understand the problem, Inputn = 4OutputExplanation − sum = T1 + T2 + T3 ... Read More

Sum of the Series 1 + x/1 + x^2/2 + x^3/3 + .. + x^n/n in C++

sudhir sharma
Updated on 01-Jul-2025 15:33:23

2K+ Views

In this article, we are given a mathematical series. Our task is to write a program to find the sum of the series 1 + x/1 + x^2/2 + x^3/3 + .. + x^n/n. This can also be represented as: $$ 1+\displaystyle\sum\limits_{k=1}^n \left(\frac{x^k}{k}\right) $$ This series without starting 1 is known as the Taylor Expansion Series for -ln(1-x) where ln is the natural log. Example Here is an example of calculating the value of the given series: Input: x = 7, n = 4 Output: 747.08 ... Read More

Sum of the series 1 + (1+3) + (1+3+5) + (1+3+5+7) + + (1+3+5+7+....+(2n-1)) in C++

sudhir sharma
Updated on 14-Aug-2020 13:50:53

516 Views

In this problem, we are given an integer n. Our task is to create a program to find the sum of the series 1 + (1+3) + (1+3+5) + (1+3+5+7) + + (1+3+5+7+....+(2n-1)).From this series, we can observe that ith term of the series is the sum of first i odd numbers.Let’s take an example to understand the problem, Inputn = 3Output 14Explanation −(1) + (1+3) + (1+3+5) = 14A simple solution to this problem is using a nested loop and then add all odd numbers to a sum variable. Then return the sum.ExampleProgram to illustrate the working of our solution, ... Read More

Sum of the series 1 + (1+2) + (1+2+3) + (1+2+3+4) + ... + (1+2+3+4+...+n) in C++

Ravi Ranjan
Updated on 16-Jul-2025 18:15:22

849 Views

In this article, we are given a number n. Our task is to write a program to calculate the sum of the series 1 + (1+2) + (1+2+3) + (1+2+3+4) + … + (1+2+3+4+...+n). This series can be represented mathematically as: $$ \displaystyle\sum\limits_{k=1}^n \displaystyle\sum\limits_{j=1}^k j $$ The above series is also known as tetrahedral number or triangular pyramidal number. A tetrahedral number is the number of points required to form a pyramid with a triangular base. Below is an example of the tetrahedral number series up to n. Scenario Consider the following example ... Read More

Sum of the series 1 / 1 + (1 + 2) / (1 * 2) + (1 + 2 + 3) / (1 * 2 * 3) + … + upto n terms in C++

Ravi Ranjan
Updated on 15-Jul-2025 18:29:51

1K+ Views

In this article, we are given an integer n. It defines the number of terms in the series: 1/1 + ( (1+2)/(1*2) ) + ( (1+2+3)/(1*2*3) ) + … + up to n terms. Our task is to write a program to calculate the sum of series 1/1 + (1+2)/(1*2) + (1+2+3)/(1*2*3) + … up to n terms. The above series can be represented as: $$ \sum_{k=1}^{n} \frac{\sum_{j=1}^{k} j}{k!} $$ Scenario The following example calculates the sum for the given series up to 4 terms: Input: n ... Read More

Sum of the series 0.7, 0.77, 0.777 … upto n terms in C++

sudhir sharma
Updated on 14-Aug-2020 13:31:55

236 Views

In this problem, we are given n terms of a number. The series is 0.7, 0.77, 0.777…. Our task is to create a program to find the sim of the series 0.7, 0.77, 0.777 … upto n terms.Let’s take an example to understand the problem, Input  4Output  Explanation −0.7 + 0.77 + 0.777 + 0.7777 = 3.0247To solve this problem, we will derive the formula for sum of series. Let’s find the general formula for it, sum = 0.7 + 0.77 + 0.777 + ... upto n terms sum = 7 (0.1 + 0.11 + 0.111 + … upto n ... Read More

Sum of the products of all possible Subsets in C++

sudhir sharma
Updated on 14-Aug-2020 13:24:44

736 Views

In this problem, we are given an array arr[] of N numbers. Our task is to create a program that will find the sum of the products of all possible subsets.Here, we will find all subsets and then find the product of all elements for each subset. Then add all the values to calculate the sum.Let’s take an example to understand the problem, Inputarr[] = {4, 5, 6}Output209Explanation −All subsets of arr[] are: {4}, {5}, {6}, {4, 5}, {5, 6}, {4, 6}, {4, 5, 6} Sum of product = (4) + (5) + (6) + (4*5) + (5*6) + (4*6) ... Read More

Queries to find whether a number has exactly four distinct factors or not in C++

Ayush Gupta
Updated on 09-Oct-2020 08:53:01

408 Views

In this problem, we are given a Q number of queries, each having a number N. Our task is to create a program to solve the Queries to find whether a number has exactly four distinct factors or not in C++.Problem DescriptionTo solve each query, we need to find whether the number N has exactly four distinct factors. If it has print YES, else No.Let’s take an example to understand the problem, Input: Q = 3, 4, 6, 15 Output: NOYES YESExplanationFor query 1: Factors of 4 are 1, 2, 4For query 2: Factors of 6 are 1, 2, 3, 6For ... Read More

Queries to find the last non-repeating character in the sub-string of a given string in C++

Ayush Gupta
Updated on 09-Oct-2020 08:55:40

184 Views

In this problem, we are given string str, and Q queries, each consisting of two integers. Our task is to create the program to solve Queries to find the last non-repeating character in the sub-string of a given string in C++.Problem DescriptionIn each query, we have two integers L and R. To solve the queries, we will take a substring starting from index L to index R. And find the last character which is non-repeating in the sub-string.Let’s take an example to understand the problem, Input: str = “Tutorialspoint” Q = 2query = {{4, 8}, {2, 6}}Output: -1 , -1ExplanationsubStr[4...8] ... Read More

Advertisements