Found 7347 Articles for C++

Eulerian Number in C++

sudhir sharma
Updated on 22-Jan-2021 13:07:32

199 Views

In mathematics, the Eulerian number is a special type of combination number. It defines the number of permutations in which the next element is a specific number greater than the previous one.Denoted as,  A(n, m) is permutation from 1 to n in which two numbers vary by m.Problem Statement: In this problem, we are given two numbers m and n. And we need to find the number of permutations that are the Eulerian Number.Let’s take an example to understand the problem, Input:  n = 4, m = 2Output: 11Explanation: All permutations of number from 1 to 4 are −1 2 3 4       ... Read More

Euler's Four Square Identity in C++

sudhir sharma
Updated on 22-Jan-2021 13:07:49

132 Views

In this problem, we are given two numbers and we need to find the product of the numbers using Euler's four square Identity. Euler’s Four Square Identity is the method to find the product of two numbers which can be represented using the sum of four squares of the number if the numbers can be represented as sum of four squares.The product a * b can be represented as the sum of four squares ifa = x12 + x22 + x32 + x42 b = y12 + y22 + y32 + y42 a * b = z12 + z22 + z32 + z42Let’s take an example ... Read More

Euler Method for solving differential equation in C++

sudhir sharma
Updated on 22-Jan-2021 13:00:01

3K+ Views

In this problem, we are given a differential equation f(x, y) = dy/dx with initial value y(x0) = y0. Our task is to find the solution of the equation using the Euler method for solving differential equations.EULER METHODEuler method also known as forward euler Method is a first order numerical procedure to find the solution of the given differential equation using the given initial value.For a differential equation f(x, y) = dy / dx. Euler method is defined as, y(n+1) = y(n) + h * f( x(n), y(n) )The value h is step size which is calculated as, h = (x(n) - x(0)) ... Read More

Equilibrium index of an array in C++

sudhir sharma
Updated on 22-Jan-2021 12:59:42

473 Views

In this problem, we are given an array arr[] consisting of n integer values. Our task is to create a program to find the equilibrium index of an array.Equilibrium Index is the index at which the sum of all elements before the index is the same as the sum of all elements after the index.For array arr[] of size n, the equilibrium index is e such that, sum (arr[0… e-1] ) = sum (arr[e… n-1])Let’s take an example to understand the problem, Input: arr[] = {5, 1, 2, 8, 3, 4, 1}Output: 3Explanation: arr[0] +  arr[1] + arr[2] = arr[4] + arr[5] + arr[6]=> ... Read More

Equidigital Numbers in C++

sudhir sharma
Updated on 22-Jan-2021 12:59:30

85 Views

Equidigital numbers are mathematically special numbers in which the number of digits in the number is equal to the number in its prime factorization.In this problem, we are given an integer value n. Our task is to create a program to all equidigital numbers up to n.Let’s take an example to understand the problem, Input: n =  12Output:  1 2 3 5 7 10 11Solution Approach:A simple solution to the problem would be finding the factors of the number and check if the number of primes is equal to the number of digits in the number .The prime factors can be ... Read More

Equalize an array using array elements only in C++

sudhir sharma
Updated on 22-Jan-2021 12:55:44

352 Views

In this problem, we are given an array of n elements. Our task is to create a program to count the number of operations to equalize an array using elements only.We need to count the number of adding or subtraction operations that will be performed to make all the elements of the array equal.Let’s take an example to understand the problem, Input: arr[] = {4, 0, 3, 1, 2}Output: 3Explanation: The equal value will be 2.The overall sum will be the same. We will be taking 1 from value at arr[3] and then adding it to value at arr[1].Then we will take 2 ... Read More

Equal Sum and XOR in C++

sudhir sharma
Updated on 22-Jan-2021 12:55:57

735 Views

In this problem, we are given an integer n. Our task is to create a program to find the count of integers from i = 0 to n, where sum is equal to XOR i.e. (n+i) = (n^i).Let’s take an example to understand the problem, Input:  n = 4Output: 4Explanation: Considering all values of i from 0 to n, i = 0,  4 + 0 = 4, 4^0 = 4i = 1,  4 + 1 = 5, 4^1 = 5i = 2,  4 + 2 = 6, 4^2 = 6i = 3,  4 + 3 = 7, 4^3 = 7i = 4, ... Read More

Equable Shapes in C++

sudhir sharma
Updated on 22-Jan-2021 12:53:47

111 Views

In this problem, we are given the coordinates of a polygon. Our task is to create a program to check whether the given polygon is equable or not.Equable Shape is the shape whose perimeter is equal to the area of the shape.Let’s take an example to understand the problem, Input: polygon[][] = {{0, 0}, {5, 7}, {2, 0}}Output: Not equableExplanation: Perimeter = 18.21Area = 7Solution Approach:The solution to the problem lies in find the area and perimeter of the shape and then compare both of them to check weather the given shape is an equable shape or not.Finding a perimeter using the coordinates is ... Read More

Enumeration of Binary Trees in C++

sudhir sharma
Updated on 22-Jan-2021 12:53:31

367 Views

Enumeration of Binary Tree is counting the total number of distinct unlabeled binary trees of a given size (specific number of nodes). In this article, we will create a program to count the number of Binary Trees of n nodes.Based on labeling of nodes of binary tree, it is of two types:Labeled Binary TreeUnlabeled Binary TreeLabeled Binary Tree: It is a binary Tree in which the nodes of a tree are labeled with values.Different Type of Labeled Binary Tree for a given number of nodes :Number of nodes N = 2Similarly, We can find the number of distinct labeled binary Tree for ... Read More

Entringer Number in C++

sudhir sharma
Updated on 22-Jan-2021 12:49:29

101 Views

Entringer Number is a special number which is equal to the number of permutations of {1, 2, 3, … n+1}, starting with K+1 which is updated by decreasing then increasing the values alternatively.The value of Entringer Number is formulated using, The recurrence relation, E(n, k) = E(n, k-1) + E(n-1, n-k)The base value is, E(0, 0) = 1E(n, 0) = 0We can find the Entringer number using, Let’s take an example to see valuesN = 5, k = 3E(5, 3) = 14Program to illustrate the working of our solution, ExampleLive Demo#include using namespace std; int EntringerNumber(int n, int k) ... Read More

Advertisements