Diagonal of a Regular Pentagon in C++ Program

Hafeezul Kareem
Updated on 27-Jan-2021 12:34:25

204 Views

In this tutorial, we are going to learn how to find the diagonal of a regular pentagon.We have to find the length of the diagonal of the regular pentagon using the given side. The length of the diagonal of a regular pentagon is 1.22 * s where s is the side of the pentagon.ExampleLet's see the code. Live Demo#include using namespace std; float pentagonDiagonal(float s) {    if (s < 0) {       return -1;    }    return 1.22 * s; } int main() {    float s = 7;    cout

Diagonal of a Regular Heptagon in C++ Program

Hafeezul Kareem
Updated on 27-Jan-2021 12:31:07

155 Views

In this tutorial, we are going to learn how to find the diagonal of a regular heptagon.We have to find the length of the diagonal of the regular heptagon using the given side. The length of the diagonal of a regular heptagon is 1.802 * s where s is the side of the heptagon.ExampleLet's see the code. Live Demo#include using namespace std; float heptagonDiagonal(float s) {    if (s < 0) {       return -1;    }    return 1.802 * s; } int main() {    float s = 7;    cout

Determine Position of Third Person on Regular N-Sided Polygon in C++

Hafeezul Kareem
Updated on 27-Jan-2021 12:30:25

146 Views

In this tutorial, we are going to learn how to find the position of a third person on a regular N-sided polygon.We have given a regular N-sided polygon. And there are two persons on two different points already. Our task is to find the third point to place the third person such that the distance between the first two persons and the third person is minimized.Let's see the steps to solve the problem.Initialize the N and two points A and B.Initialize the position of the third person, and the minimum sum to find the position.Iterate from 1 to N.If the ... Read More

Determinant of a Matrix in C++ Program

Hafeezul Kareem
Updated on 27-Jan-2021 12:27:40

6K+ Views

In this tutorial, we are going to learn how to find the determinant of a matrix.Let's see the steps to find the determinant of a matrix.Initialize the matrix.Write a function to find the determinant of the matrix.If the size of the matrix is 1 or 2, then find the determinant of the matrix. It's a straightforward thing.Initialize variables for determinant, submatrix, sign.Iterate from 1 to the size of the matrix N.Find the submatrix for the current matrix element.All the elements that are not in the current element row and columnAdd the product of the current element and its cofactor to ... Read More

Deserium Number with Examples in C++ Program

Hafeezul Kareem
Updated on 27-Jan-2021 12:26:05

149 Views

In this tutorial, we are going to learn about the deserium numbers with examples.The number whose sum of pow(digit, digitsCount) is equal to the given number is called Deserium number.Let's see the steps to find whether the given number is deserium number or not.Initialize the number.Find the digits count of the number.Initialize a variable to store the sum.Iterate until the number is less than 0.Get the last digit by diving the number with 10.Add the pow(digit, digitsCount) to the sum.If the sum is equal to the number, then it is deserium number else it is not.ExampleLet's see the code. Live Demo#include ... Read More

Depth of the Deepest Odd Level Node in Binary Tree in C++

Hafeezul Kareem
Updated on 27-Jan-2021 12:24:53

146 Views

In this tutorial, we are going to learn how to find the deepest odd level node in a binary tree.This is similar to finding the depth of the binary tree. Here, we have to one more condition i.e.., whether the current level is odd or not.Let's see the steps to solve the problem.Initialize the binary tree with dummy data.Write a recursive function to find the deepest odd level node in a binary tree.If the current node is a leaf node and the level is odd, then return the current level.Else return the max of left node and right node with ... Read More

Depth of an N-ary Tree in C++

Hafeezul Kareem
Updated on 27-Jan-2021 12:22:15

1K+ Views

In this tutorial, we are going to learn how to find the depth of the n-ary tree.An n-ary tree is a tree in which each node of the tree has no more than n child nodes.We have to find the depth of the n-ary tree. We will be using the vector to store the children of each node in the tree.Let's see the steps to solve the problem.Initialize the tree with dummy data.Write a recursive function to find the depth of the n-ary tree.Initialize a variable to store the max depth of the tree.Iterate over the children of each node.The ... Read More

Density of Binary Tree in One Traversal in C++

Hafeezul Kareem
Updated on 27-Jan-2021 12:20:55

274 Views

In this tutorial, we are going to learn how to find the density of the binary tree in a single traversal.The density of the binary tree is obtained by dividing the size of the tree by the height of the tree.The size of the binary tree is the total number of nodes present in the given binary tree.The height of the binary tree is the max depth of the leaf node from the root node.Let's see the steps to solve the problem.Initialize the binary tree dummy data.Find the size and height of the tree.Recursively count the height of the tree.Return ... Read More

Demlo Number Square of 11 in C++ Program

Hafeezul Kareem
Updated on 27-Jan-2021 12:19:32

232 Views

In this tutorial, we are going to learn about the demlo number.The demlo numbers are the squares of the number 1, 11, 111, 1111, etc.., We can easily find the demlo number as it is in the form 1 2 3 4 5 ... n-2 n-1 n n-1 n-2 ... 5 4 3 2 1.Here, we are given a number which has only ones. And we need to find the demlo number of that number. Let's see an example.Input − 1111111Output − 1234567654321Let's see the steps to solve the problem.Initialize the number in a string format.Initialize an empty string to ... Read More

Deletions of 01 or 10 in Binary String in C++

Hafeezul Kareem
Updated on 27-Jan-2021 12:15:32

255 Views

In this tutorial, we are going to write a program that finds the total number of pairs (01 or 10) to free the binary string from the pairs (01 and 10). Let's see an example.Input − 101010001Output − 4In the above example, we have to delete a total of 4 pairs to free the binary string from the pairs (01 and 10).The resultant string after deleting all the pairs is 0.We have to delete all the 01 and 10 pairs from the binary string. So, the total number of pairs to be deleted is the minimum of count(1) and count(0).Let's ... Read More

Advertisements