Found 7347 Articles for C++

Evil Number with Example in C++

sudhir sharma
Updated on 22-Jan-2021 13:17:29

555 Views

In this problem, we are given an array a number N. Our task is to check whether the number is an evil Number or Odious Number. Evil Number: It is a positive number which has an even number of 1’s in its binary expansion.Example: 5, 17 Odious Number: It is a positive number which has an odd number of 1’s in its binary expansion.example : 4, 6Let’s take an example to understand the problem, Input: N = 65Output: Evil NumberExplanation: Binary Expansion of 65 :  1000001Solution Approach: A simple solution to the problem is by finding the binary expansion of the number and then counting the number of 1’s ... Read More

Even-odd turn game with two integers in C++

sudhir sharma
Updated on 22-Jan-2021 13:16:29

193 Views

In this problem, we are given three integer values A , B and T. Our task is to create a program to play Even-odd turn game with two integers. The two integer value are :T, that denotes the number of turns in the game.A denotes the value for player1B denotes the value for player2If the value of T is odd, the value of A is multiplied by 2.If the value of T is even, the value of B is multiplied by 2.We need to find and return value of max(A, B) / min(A, B) at the end.Let’s take an example to understand ... Read More

Even size subtree in n-ary tree in C++

sudhir sharma
Updated on 22-Jan-2021 13:15:47

104 Views

In this problem, we are given an adjacency list that denotes an n-ary tree. Our task is to find the number of even size subtree in n-ary tree. N-ary tree is defined as a collection of nodes normally represented hierarchically in the following manner.The tree is started at the root node.Each node of the tree maintains a list of pointers to its child nodes.The number of child nodes is less than or equal to m.Let’s take an example to understand the problem, Input: Output: 4Explanation: Tree rooted with 7 has an even size.Tree rooted with 2 has an even size.Tree rooted with 0 has an ... Read More

Even numbers at even index and odd numbers at odd index in C++

sudhir sharma
Updated on 22-Jan-2021 13:16:18

877 Views

In this problem, we are given an array arr[] of size n consisting of n/2 even values and n/2 odd values. Our task is to create a program to place even numbers at even index and odd numbers at odd index. Let’s take an example to understand the problem, Input: arr[] = {5, 1, 6, 4, 3, 8}Output: arr[] = {6, 1, 5, 4, 3, 8}Solution Approach −A solution would be traversing the array and then find the end number which is not at even position and replacing it with the next off place value. This is a promising solution but the solution ... Read More

Evaluation order of operands in C++

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

168 Views

There are some rules in programming that govern how an operation is performed.The order of evaluation of operation and the associativity of operations (which is left to right is defined).Here is a program to show the evaluation order of operands,ExampleLive Demo#include using namespace std; int x = 2; int changeVal() {    x *= x;    return x; } int main() {        int p = changeVal() + changeVal();    cout

Evaluation of Risk in Investments in C++

sudhir sharma
Updated on 22-Jan-2021 13:16:43

99 Views

In this problem, we are given two arrays each denoting an investment plan. Our task is to perform the evaluation of Risk in Investment and find which of the two investments is more promising.Both the investments I1[][] and I2[][] has a set of outcomes and the probability of that investment outcome.Using these values, we need to find the risk in each investment and then print the better investment out of the two investments.For this, we will be using statistical mathematics and find some values that will help us conclude to the better investment.We will find these values, Mean or average amount ... Read More

Evaluation of Expression Tree in C++

sudhir sharma
Updated on 22-Jan-2021 13:13:21

893 Views

In this problem, we are given an expression tree that consist of binary operations like +, - , /, *. We need to do the evaluation of the expression tree and then return the result.Expression Tree is a special type of binary tree in which each node either consist of an operator or operand which are distributed as−Leaf nodes of the tree are values on which the operation is to be performed. Non-leaf nodes consist of the binary operator denoting the operation to be performed. Let’s take an example to understand the problem, Input: Output: 1Explanation: Decoding the expression tree, Exp           ... Read More

Evaluation of Prefix Expressions in C++

sudhir sharma
Updated on 22-Jan-2021 13:13:40

13K+ Views

In this article, we will discuss the evaluation of prefix Expression. Prefix ExpressionIn this notation, operator is prefixed to operands, i.e. operator is written ahead of operands. For example, +ab. This is equivalent to its infix notation a + b. Prefix notation is also known as Polish Notation.For more read.Example:* + 6 9 - 3 1Prefix expressions are evaluated faster than infix expressions. Also, there are no brackets in prefix expressions which make it evaluate quicker.Algorithm to evaluate Prefix Expression:The evaluation of prefix expression requires a stack data structure. We will push the operators in the stack and then solve the ... Read More

Evaluate an array expression with numbers, + and - in C++

sudhir sharma
Updated on 22-Jan-2021 13:13:55

213 Views

In this problem, we are given an array arr[] consisting of n character values denoting an expression. Our task is to evaluate an array expression with numbers, + and –. The expression consists of only, numbers, ‘+’ character and ‘- ’ character.Let’s take an example to understand the problem, Input: arr = {“5”, “+”, “2”, “-8”, “+”, “9”, }Output: 8Explanation: The expression is 5 + 2 - 8 + 9 = 8Solution Approach:The solution to the problem is found by performing each operation and then returning the value. Each number needs to be converted to its equivalent integer value.Program to illustrate the working of ... Read More

Evaluate a boolean expression represented as string in C++

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

584 Views

In this problem, we are given a string exp that represents a boolean expression. Our task is to evaluate the boolean expression represented as String.The valid characters in the expression are −0 or 1 denoting the boolean value& denoting AND operation| denoting OR operation^ denoting XOR operationWe need to solve this expression and return the result.Let's take an example to understand the problem, Input: str = 1&1|0^1^0&1Output: 0Explanation: 1&1|0^1^0&11 AND 1 OR 0 XOR 1 XOR 0 AND 11 OR 0 XOR 1 XOR 0 AND 11 XOR 1 XOR 0 AND 10 XOR 0 AND 10 AND 10Solution Approach:A simple solution is ... Read More

Advertisements