Find Second Most Frequent Character in C++

Ayush Gupta
Updated on 17-Sep-2020 05:00:42

859 Views

In this problem, we are given string str. Our task is to create a Program to find second most frequent character in C++.Let’s take an example to understand the problemInputstr = “abaacabcba”Output‘b’Solution ApproachTo find the character that is second most frequent in the string. We need to maintain a count array chatCount that is used to store the frequency of each character in the string. And then using the array we will find the character with max and secondMax frequency in the array. And display the second most frequent character.Program to illustrate the working of our solutionExample Live Demo#include #include ... Read More

Find Size of Doubly Linked List in C++

Ayush Gupta
Updated on 17-Sep-2020 04:57:41

620 Views

In this problem, we are given a doubly linked list. Our task is to create a program to find size of Doubly Linked List in C++.Doubly Linked List is a special type of Linked list in which navigation is possible in both ways, either forward and backward easily as compared to Single Linked List. The following are the important terms to understand the concept of doubly linked lists.Link − Each link of a linked list can store a data called an element.Next − Each link of a linked list contains a link to the next link called Next.Prev − Each ... Read More

Find Smallest and Largest Word in a String in C++

Ayush Gupta
Updated on 17-Sep-2020 04:50:56

4K+ Views

In this problem, we are given string str. Our task is to create a program to find Smallest and Largest Word in a String in C++.Problem Description − Here, we have a string we need to find the word whose length is maximum and minimum out of all words in the string. The word is separated using white spaces or null(\0) characters.Let’s take an example to understand the problemInputstr = “Learn Programming at TutorialsPoint”Outputsmallest word = at largest word = TutorialspointSolution ApproachTo find the smallest and largest word, we will find the length of each word by using two indexes, ... Read More

Find Star Number in C++

Ayush Gupta
Updated on 17-Sep-2020 04:47:24

171 Views

In this problem, we are given a number n. Our task is to create a program to find Star number in C++.Star Number is a special number that represents a centered hexagram (sixpoint star).Some start numbers are 1, 13, 37, 73, 121.Let’s take an example to understand the problemInputn = 5Output121Solution ApproachTo find the nth star number we will use the formula.Let’s see the general formula for the star number.n = 2 -> 13 = 12 + 1 = 6(2) + 1 n = 3 -> 37 = 36 + 1 = 6(6) + 1 n = 4 -> 73 ... Read More

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

Ayush Gupta
Updated on 17-Sep-2020 04:45:55

313 Views

In this problem, we are given two values x and n that corresponds to the given series. Our task is to create a program to find sum of 1 + x/2! + x^2/3! +…+x^n/(n+1)! in C++.Problem description − we need to find the sum of series based on the given values of x and n. In the series, every other term differs from the previous term by x/i for ith term.Let’s take an example to understand the problemInputx = 6, n = 4Output29.8ExplanationThe sum of the series is1 + 6/2 + 36/6 + 216/24 + 1296/120 = 29.8Solution ApproachTo find ... Read More

Find Sum of a Series in C++

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

617 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

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

Find Sum of Harmonic Series in C++

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

988 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

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

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

Advertisements