Found 7197 Articles for C++

Create Maximum Number in C++

Arnab Chakraborty
Updated on 01-Jun-2020 10:35:46

232 Views

Suppose we have two arrays of length m and n with digits 0-9 representing two numbers. We have to create the maximum number of length k that is less than m + n from digits of the two. We have to keep in mind that the relative order of the digits from the same array must be preserved. We have to find the array of the k digits. So if the inputs are like [3, 4, 7, 5] and [9, 1, 3, 5, 8, 4], and k = 5, then the answer will be [9, 8, 7, 5, 4].To solve ... Read More

Program to find the angles of a quadrilateral in C++

Ayush Gupta
Updated on 16-Sep-2020 17:31:28

261 Views

In this problem, we are given a value d, which is the common difference of AP. This AP is all the angles of a quadrilateral. Our task is to create a program to find the angles of a quadrilateral in C++.Problem Description − Here, the angles of the quadrilateral are in the form of an AP with common difference d. And we need to find the angles.Let’s take an example to understand the problemInputd = 15Output67.5, 82.5, 97.5, 112.5ExplanationFirst angle is x Second angle is x + 15 Third angle is x + 30 Four angle is x + 45Sum ... Read More

Program to find sum of series 1 + 2 + 2 + 3 + 3 + 3 + .. + n in C++

Revathi Satya
Updated on 22-May-2024 11:51:40

726 Views

In this article, we are given a number n that denotes the nth term of the series. Our task is to create a Program to find sum of series 1 + 2 + 2 + 3 + 3 + 3 + .... + n in C++. This series is different from the other because it include terms that are repeated according to their values. The series 1 + 2 + 2 + 3 + 3 + 3 + … + n consists of repeated terms that are repeated infinitely only by their value. Such illustration 1 comes once, ’2 twice’, ... Read More

Program to find sum of series 1 + 1/2 + 1/3 + 1/4 + .. + 1/n in C++

Ayush Gupta
Updated on 16-Sep-2020 17:39:13

4K+ Views

In this problem, we are given a number n. Our task is to create a program to find sum of series 1 + 1/2 + 1/3 + 1/4 + .. + 1/n in C++.Code description − Here, we will find the sum of the series 1 + 1/2 + 1/3 + 1/4 + .. + 1/n till nth term. The series is a harmonic progression series.Harmonic progression is a series whose inverse will be an arithmetic progression. I.e. if for a harmonic progression A1, A2, A3... An, there is an arithmetic progression 1/A1, 1/A2, 1/A3.First, let’s take an example to ... Read More

Program to find sum of prime numbers between 1 to n in C++

Ayush Gupta
Updated on 16-Sep-2020 17:41:06

4K+ Views

In this problem, we are given a number n. Our task is to create a program to find sum of prime numbers between 1 to n in C++.Prime Numbers are those numbers that have only two factors. They are the number and 1.Let’s take an example to understand the problemInputn = 15Output41ExplanationPrime numbers between 1 to 15 are 2, 3, 5, 7, 11, 13. The sum is 41.Solution ApproachA simple way to solve the problem is by using a loop and checking if each number is a prime number or not and add all those which are prime.To check if ... Read More

Program to find sum of harmonic series in C++

Ayush Gupta
Updated on 16-Sep-2020 17:42:44

968 Views

In this problem, we are given three numbers a, d, and n. Our task is to create a program to find sum of harmonic series in C++.Harmonic progression is a series whose inverse will be an arithmetic progression. I.e. if for a harmonic progression A1, A2, A3.. An, there is an arithmetic progression 1/A1, 1/A2, 1/A3.So, a general HP is1/a, 1/(a+d), 1/(a+2d), … 1/(a + nd)Where 1/a is the first term. And d is the common difference of the reversed AP.Problem Description − Here, we will be given the first term a, common difference d, and the number of terms ... Read More

Program to find sum of given sequence in C++

Revathi Satya
Updated on 22-May-2024 11:50:23

846 Views

In this article, we are given two numbers n and k representing a series. Our task is to create a program in C++ that finds the sum of the sequence given below: The input cycle is the process of adding up all the numbers in the given sequence to get a single output. The process of recursion is frequently used in mathematics and may be implemented with sequences namely the arithmetic ones ( each term is acquired by adding a constant difference between the previous one) and the geometric sequence ( where each term is multiplied by a constant ratio with the former term ... Read More

Program to find sum of first n natural numbers in C++

Ayush Gupta
Updated on 27-May-2020 09:39:58

399 Views

In this tutorial, we will be discussing a program to find sum of first n natural numbers.For this we will be provided with an integer n. Our task is to add up, find the sum of the first n natural numbers and print it out.Example Live Demo#include using namespace std; //returning sum of first n natural numbers int findSum(int n) {    int sum = 0;    for (int x=1; x

Program to find sum of elements in a given array in C++

Ayush Gupta
Updated on 16-Sep-2020 17:47:42

1K+ Views

In this problem, we are given an array arr[] of n integer values. Our task is to create a Program to find sum of elements in a given array in C++.Program Description − For the given array, we will add up all elements and return the sum.Let’s take an example to understand the problemInputarr[] = {3, 1, 7, 2, 9, 10}Output32ExplanationSum = 3 + 1 + 7 + 2 + 9 + 10 = 32Solution ApproachTo find the sum of elements of the array, we will traverse the array and extract each element of the array and add them to ... Read More

Program to find Sum of a Series a^1/1! + a^2/2! + a^3/3! + a^4/4! +…….+ a^n/n! in C++

Ayush Gupta
Updated on 16-Sep-2020 17:48:57

608 Views

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 problemInputa = 3, n = 4Output15.375Explanationsum of series is(3^1)/1! + (3^2)/2! + (3^3)/3! + ... Read More

Advertisements