Found 7197 Articles for C++

Possible number of Rectangle and Squares with the given set of elements in C++

sudhir sharma
Updated on 17-Apr-2020 07:37:24

349 Views

In this problem, we are given an array of N integers denoting the length of n sticks. Our task is to print the count of rectangles and squares that can be created from the sticks of the given length.Let’s take an example to understand the problemInput − array = {5, 5, 7, 7, 1, 4}Output − 1Explanation − a rectangle with sides 5 5 7 7.To solve this problem, we will have to check if rectangles and squares are possible or not.Now, for creating a square or rectangle, there should be two sticks of the same length, 2 for rectangle and 4 for ... Read More

Possible timings in C++

sudhir sharma
Updated on 17-Apr-2020 07:29:13

69 Views

In this problem, we are given two-digit timing using a glow digit display or seven-segment display (as in calculator). Our task is to calculate the possibility of occurrence of other timings that can occur by glowing or deleting one bit of the display.Seven-segment display is a special display that is used to display digits by glowing lines of the display.Sample of the seven-segment display is −Let’s take an example to understand the problem, Input − 7 5Output −Explanation − For 7, 5 numbers can be used to replace it. They are 9, 3, 8, 0, 7. For 5, 4 numbers ... Read More

Possible to form a triangle from array values in C++

sudhir sharma
Updated on 17-Apr-2020 07:26:45

4K+ Views

In this problem, we are given an array of integers. Our task is to check if the creation of a non-degenerate triangle taking the elements of the array as sides of the triangle.Non-degenerate triangle − it is a triangle that has a positive area. The condition for a non-degenerate triangle with sides a, b, c is −a + b > c a + c > b b + c > aLet’s take an example to understand the problem better −Input − arr[2, 5 ,9, 4, 3]Output − YesExplanation − the triangle formed is 2 3 4.To solve this problem, we ... Read More

Possible to make a divisible by 3 number using all digits in an array in C++

sudhir sharma
Updated on 17-Apr-2020 07:23:54

647 Views

In this problem, we are given an array. Our task is to check whether a number generated by using all digits of the elements of the array is divisible by 3. If possible then print “Yes” otherwise print “No”.Let’s take an example to understand the problemInput − arr = {3, 5, 91, }Output − YESExplanation − The number 5193 is divisible by 3. So, our answer is YES.To solve this problem, we will check its divisibility by 3.Divisibility by 3 − a number is divisible by 3 if the sum of its digits is divisible by 3.Now, we will have ... Read More

Possible two sets from first N natural numbers difference of sums as D in C++

sudhir sharma
Updated on 17-Apr-2020 07:21:44

86 Views

In this problem, we are given two integer N and D. Our task is to check whether it is possible to have to sets from the set of first N natural numbers that have a difference of D.Let’s take an example to understand the problem, Input − N=5 D =3Output − YesExplanation −Out of 1, 2, 3, 4, 5. We can have two sets set1= {1, 2, 3} and set2 = {4, 5}, this will give difference 3. {4+5} - {1+2+3} = 9- 6 = 3For solving this problem, we will have some mathematical calculations.We know, the sum of all number ... Read More

Postfix to Infix in C++

sudhir sharma
Updated on 17-Apr-2020 07:15:33

5K+ Views

In this problem, we are given expression in postfix form and our task is to print the infix form of the expression.Infix expression is an expression in which the operator is in the middle of operands, like operand operator operand.Postfix expression is an expression in which the operator is after operands, like operand operator.Postfix expressions are easily computed by the system but are not human readable. So this conversion is required. Generally reading and editing by the end-user is done on infix notations as they are parenthesis separated hence easily understandable for humans.Let’s take an example to understand the problemInput ... Read More

Postorder successor of a Node in Binary Tree in C++

sudhir sharma
Updated on 17-Apr-2020 07:12:30

725 Views

In this problem, we are given a binary tree and node. Our task is to print the postorder successor of the node in Binary tree.Binary tree is a special type of tree in which each node can have at max 2 child nodes.Postorder Traversal is a tree traversal technique, in which the first left subtree is traversed than the right subtree and the root is traversed at the end.postorder traversal of the above tree: 8 4 2 7 9 6Let’s take an example to understand the problem.Input − binary tree in above example, node= 7Output − 9Explanation − we can ... Read More

Postorder traversal of Binary Tree without recursion and without stack in C++

sudhir sharma
Updated on 17-Apr-2020 07:03:44

452 Views

In this problem, we are given a Binary tree. Our task is to print the postorder traversal of the binary tree without using recursion and without stack.Binary tree is a special type of tree in which each node can have at max 2 child nodes.Postorder Traversal is a tree traversal technique, in which the first left subtree is traversed than the right subtree and the root is traversed at the end.postorder traversal of the above tree − 8 4 2 7 9 6To traverse the tree without using recursion and stack. We will depth-first search based technique and data will ... Read More

pow() function for complex number in C++

sudhir sharma
Updated on 17-Apr-2020 06:58:09

712 Views

pow() or power function is a function used to calculate the power of a number. It is generally used in real numbers. Here, we will see its implementation of complex numbers.Complex numbers are those numbers that can be represented as A + iB, where A is the real part and B is the complex part of the number.The functions for the complex number in c++ are defined in the header file . Here, the pow() method for complex numbers is defined. It finds the complex power of a complex number to some power.The method is applied to complex numbers takes ... Read More

Power in Mathematics in C++

sudhir sharma
Updated on 17-Apr-2020 06:55:32

169 Views

The power of a number is the times a number is multiplied to itself. Also knows as exponent or indices.a to the power b is b times a is multiplied by itself b times. 7 to the power 2 is 72 also known as 7 square is valued 49.Some common power values are −A number to the power 0 gives 1.A number to the power 1 gives the same number, as stated some multiplied once is the same.A number to the negative power is n times division. Example, a -3 = 1/a3 or (1/a)*(1/a)*(1/a)Now, let’s do some programming based on ... Read More

Advertisements