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++ Articles - Page 304 of 719
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
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
528 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
865 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
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
248 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
761 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
418 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
190 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
402 Views
In this problem, we are given an array arr[] and Q queries. Each Query can be one of 2 types, 1st to find the maximum pair product in a given range [ Start - End ]. 2nd to update the ith index element with value. Our task is to create a program to solve Queries to find maximum product pair in range with updates in C++.Let’s take an example to understand the problem, Input:arr = {4, 2, 6, 9, 1}Q = 3Q1 = [1, 1, 4]Q2 = [2, 2, 3]Q3 = [1, 0, 2]Output: 54, 12ExplanationFor query 1, type 1: range ... Read More