Found 7347 Articles for C++

Sum of XOR of all possible subsets in C++

sudhir sharma
Updated on 17-Aug-2020 10:00:52

336 Views

In this problem, we are given an array aar[] of n numbers. Our task is to create a program to find the Sum of XOR of all possible subsets.Here, we will find all subsets of the array. Then for each subset, we will find the XOR of elements of the subset and add them to the sum variable.Let’s take an example to understand the problem, Input: arr[] = {5, 1, 4} Output: 20 Explanation: XOR of all subsets: {5} = 5 {1} = 1 {4} = 4 {5, 1} = 4 {5, 4} = 1 {1, 4} = 5 {5, ... Read More

Sum of XOR of all pairs in an array in C++

sudhir sharma
Updated on 17-Aug-2020 09:58:43

2K+ Views

In this problem, we are given an array arr[] of n integers. Our task is to create a program to find the sum of XOR of all pairs in an array.Let’s take an example to understand the problem, Input: arr[] = {5, 1, 4} Output: 10 Explanation: the sum of all pairs: 5 ^ 1 = 4 1 ^ 4 = 5 5 ^ 4 = 1 sum = 4 + 5 + 1 = 10One simple approach to solve this problem is to run nested loops and find all pairs of numbers. Find XOR of each pair and add ... Read More

Sum of upper triangle and lower triangle in C++

sudhir sharma
Updated on 17-Aug-2020 09:49:49

871 Views

In this problem, we are given a matrix. Our task is to create a program to print the sum of upper triangle and lower triangle.Lower triangleM00                     0             0       …        0 M10                     M11               0       …        0 M20                     M21               M22      …     ... Read More

Maximum number with same digit factorial product in C++

Sunidhi Bansal
Updated on 17-Aug-2020 09:26:44

88 Views

Given the task is to find the maximum number without any leading or trailing zeroes or ones whose product of factorial of its digits is equal to the product of factorial of digits of the given number N.Let’s now understand what we have to do using an example −Input − N = 4912Output − 73332222Explanation − 4! * 9! * 1! * 2! = 7! * 3! * 3! * 3! * 2! * 2! *2! *2! = 17, 418, 240Input − N = 340Output − 3322Approach used in the below program as followsIn order to attain the maximum answer ... Read More

Maximum number that can be display on Seven Segment Display using N segments in C++

Sunidhi Bansal
Updated on 17-Aug-2020 09:24:08

259 Views

Given the task is to find the maximum number that can be displayed using N segment on ant number of seven segment display.Let’s now understand what we have to do using an example −Input − N=5Output − 71Explanation − The largest number will be displayed as follows on the seven segment display −Input − N=6Output − 111Approach used in the below program as followsThe following situation can be divided into 3 case −Case 1 −If N is 0 or 1, then it is not possible to display any number.Case 2 −If N is odd. Then the numbers that can be ... Read More

Maximum number of Zombie processes a system can handle in C++

Sunidhi Bansal
Updated on 17-Aug-2020 09:21:18

126 Views

Given the task is to find the maximum number of Zombie processes that a system can handle or in other words, the program does not stop its execution.A Zombie process (also known as defunct process) is a process that has completed its process via exit() (system call) but still has an entry in the process table.Approach used in the below program as followsNote that should be added in order to run the program.In main() function initialize num = 0 of type int which we will iterate until the program stops being executed.To initiate a zombie process create a while statement ... Read More

Sum of two numbers modulo M in C++

sudhir sharma
Updated on 17-Aug-2020 09:40:20

488 Views

In this problem, we are given three numbers a, b, and M. our task is to create a program to find the sum of two numbers modulo M.Let’s take an example to understand the problem, Input: a = 14 , b = 54, m = 7 Output: 5 Explanation: 14 + 54 = 68, 68 % 7 = 5To solve this problem, we will simply add the numbers a and b. And then print the remainder of the sum when divided by M.ExampleProgram to illustrate the working of our solution,  Live Demo#include using namespace std; int moduloSum(int a, int ... Read More

Maximum number of unique prime factors in C++

Sunidhi Bansal
Updated on 17-Aug-2020 09:20:03

985 Views

Given the task is to find the maximum number of unique prime factors a number can have in the range of [1, N] where N is given.Let’s now understand what we have to do using an example −Input − N=100Output − 3Explanation − Let us take 30 in the range of [1, 100]30 = 3 * 2 * 5 = unique prime factors. Therefore, in the range of [1, 100] a maximum of 3 unique factors can be found.Input − N=300Output − 4Approach used in the below program as followsIn function MaxPrime() we will first check if (N < 2). ... Read More

Maximum number of trailing zeros in the product of the subsets of size k in C++

Sunidhi Bansal
Updated on 17-Aug-2020 09:18:22

159 Views

Given the task is to find the maximum number of trailing zeroes in the product of the subsets of size K, of a given array of size N.Let’s now understand what we have to do using an example −Input − Arr[] = {5, 20, 2} , K=2Output − 2Explanation − A total of 3 subsets can be created having size = 2.The product of [5, 20] is 100.The product of [20, 2] is 40.The product of [5, 2] is 10.100 has the maximum number of trailing zeros = 2. Therefore 2 is the answer.Input − Arr[] = {60, 40, 25} ... Read More

Maximum number of segments of lengths a, b and c in C++

Sunidhi Bansal
Updated on 17-Aug-2020 09:16:11

189 Views

Given the task is to find the maximum number of line segments of lengths a, b and c that can be formed from given positive integer N.Let’s now understand what we have to do using an example −Input − N=8, a=3, b=1, c=2Output − 8Explanation − N can be divided into 8 segments of b which is maximum number of segments that can be made.Input − N=13, a=2, b=7, c=3Output − 6Approach used in the below program as followsIn function MaxSegment() declare an array MaxSeg[N +1] of type int and initialize it with value -1.The put the zero-th index equal ... Read More

Advertisements