Found 7346 Articles for C++

Find the Number of Prime Pairs in an Array using C++

Prateek Jangid
Updated on 24-Nov-2021 11:03:12

256 Views

In this article, we will explain everything about finding the number of prime pairs in an array using C++. We have an array arr[] of integers, and we need to find all the possible prime pairs present in it. So here is the example for the problem −Input : arr[ ] = { 1, 2, 3, 5, 7, 9 } Output : 6 From the given array, prime pairs are (2, 3), (2, 5), (2, 7), (3, 5), (3, 7), (5, 7) Input : arr[] = {1, 4, 5, 9, 11} Output : 1Approaches to Find ... Read More

Find the Number of Prefix Sum Prime in Given Range Query using C++

Prateek Jangid
Updated on 24-Nov-2021 08:03:58

200 Views

In this article, we need to find a number of prefix sum which are prime numbers in a given array arr[ ] of positive integers and range query L, R, where L is the initial index value arr[ L ] for prefixsum[ ] array and R is the number of prefix sum we need to find.To fill the prefix sum array, we start with index L to index R and add the present value with the last element in the given array. So here is the Example for the problem −Input : arr[ ] = { 3, 5, 6, 2, ... Read More

Find the Number of Possible Pairs of Hypotenuse and Area to Form Right Angled Triangle using C++

Prateek Jangid
Updated on 24-Nov-2021 07:57:31

134 Views

In this article, we will explain how to solve the number of possible pairs of hypotenuse and area form a right-angled triangle in C++.We need to determine the number of all possible pairs of a hypotenuse and the area ( H, A ) to form a right-angled triangle with H as hypotenuse and A as Area.In this example −         x = Base of Right Angled Triangle         y = Height of Right Angled Triangle         H = hypotenuse of Right Angled TriangleWe know Area of right angled triangle, A = ( x * ... Read More

Find the Number of permutation with K inversions using C++

Prateek Jangid
Updated on 24-Nov-2021 07:36:22

294 Views

In an array, A pair a[i], a[j] is known as an inversion if a[i] > a[j] and i < j. We have two numbers N and k, and need to figure out how many possible permutations of the first N numbers end in a perfect K inversion. So here is the example −Input: N = 4, K = 1 Output: 3 Explanation: Permutation of the first N numbers in total : 1234, 1243, 1324 and 2134. With 1 inversion we have 1243, 1324 and 2134. Input : N = 3, K = 2 Output : 3 Explanation: Permutation of ... Read More

Find the Number of Pentagons and Hexagons on a Football using C++

Prateek Jangid
Updated on 24-Nov-2021 07:27:22

191 Views

As we all know, pentagons and hexagons are equally essential parts of football. These shapes fit together like a puzzle for forming a perfectly spherical shape. So here we have a football, in which we have to find the hexagons and pentagons.We will use the Euler characteristic to solve the problem easily. Euler characteristic is a number that works to describe a specific shape or structure of any topological space. So we can use it for calculating the number of Pentagons and Hexagons on the football.In Euler characteristics −chi(S) − Integer for a specific surface SF − facesG − GraphV ... Read More

Find the Number of Paths of Weight W in a K-ary tree using C++

Prateek Jangid
Updated on 24-Nov-2021 07:22:58

120 Views

In this article, we'll use C++ to calculate the number of weight W paths in a K-ary tree in this article. We've given a K-ary tree, which is a tree in which each node has K children and each edge has a weight assigned to it, with weights descending from 1 to K from one node to all of its children.We need to count the cumulative number of paths beginning from the root that have a weight of W and at least one edge with a weight of M. So, here's example −Input : W = 4, K = 3, ... Read More

Find the Nth Number Made Up of only Odd Digits using C++

Prateek Jangid
Updated on 23-Nov-2021 10:35:12

470 Views

C++ has a huge list of functions to solve mathematical issues. One of the mathematical functions is to find Nth odd digits using codes. This article will describe the complete approach of finding the odd Nth number and understand what odd numbers are and what numbers are made up of odd digits.Finding the Nth Number Made up of Odd Digits OnlyOdd numbers give remainder on dividing by two, so the first few odd numbers are 1, 3, 5, 7, 9, 11, 13, 15, 17, 19...To find the required number, we have two approaches here −Approach 1 − Check every natural ... Read More

Find the Nth_Non_Square_Number using C++

Prateek Jangid
Updated on 23-Nov-2021 10:35:55

163 Views

We all know about the numbers that are not square of any number like 2, 3, 5, 7, 8, etc. There are Nth numbers of non-square numbers, and it is impossible to know every number. So In this article, we will explain everything about the square-free number or non-square number and what are the ways to find Nth non-square number in C++.Nth Non-Square NumberA number is said to be a perfect square if it is a square of an integer. Some example of perfect square numbers are −1 is square of 1 4 is square of 2 9 is square ... Read More

Merge Sort using Multithreading in C++

Sunidhi Bansal
Updated on 05-Nov-2021 07:04:34

4K+ Views

We are given an unsorted integer array. The task is to sort the array using merge sort technique implemented via Multi-threadingMerge SortMerge sort is a sorting technique which is based on divide and conquer technique where we divide the array into equal halves and then combine them in a sorted manner.Algorithm to implement merge sort ischeck if there is one element in the list then return the element.Else, Divide the data recursively into two halves until it can’t be divided further.Finally, merge the smaller lists into new lists in sorted order.Multi-ThreadingIn the operating system, Threads are the lightweight process which ... Read More

Merge Sort Tree in C++

Sunidhi Bansal
Updated on 05-Nov-2021 07:20:07

488 Views

We are given an integer array, a set of segment start and end pointers and a key value and the problem statement here is to find all the values in the given range which are smaller than or equal to the given key value.Let us understand with exampleInput − arr[] = {7, 8 , 1, 4 , 6 , 8 , 10 }Segment 1: start = 2, end = 4, k = 2Segment 2: start = 1, end = 6, k = 3Output − Count of number which are smaller than or equal to key value in the given range are 2 ... Read More

Advertisements