Found 7197 Articles for C++

Write a program for Happy Woman’s Day in c++

Ajay yadav
Updated on 29-Nov-2019 10:35:27

451 Views

The woman day which is celebrated on 7th October worldwide is carved into a c++ programming code as following;Example#include using namespace std; int main(){    // Initializing size of    // design    int n = 5;    // Loop to print Circle    // (Upper part of design)    // Outer loop to    // control height of    // design    for (int i = 0; i

Difference between Go and C++.

Mahesh Parahar
Updated on 28-Nov-2019 10:46:55

385 Views

GoGo is a procedural programming language. Programs are assembled using packages. It supports environment adopting patterns similar to dynamic languages.C++C++ is an object oriented programming language. C++ is quiet fast, reliable and secure. It is most widely used language as well.Following are the important differences between Go and C++.Sr. No.KeyGoC++1TypeGo is a procedural programming language and supports patterns similar to dynamic languages.C++ is an object oriented programming language.2Supports for ClassGo has no support for class with constructors.C++ has support for class with constructors.3Garbage CollectionGo has automatic garbage collection.C++ has not provided automatic garbage collection.4InheritanceGo has no support for inheritance.C++ supports ... Read More

Minimum operations required to set all elements of binary matrix in C++

Narendra Kumar
Updated on 22-Nov-2019 11:58:52

232 Views

Problem statementGiven a binary matrix of N rows and M columns. The operation allowed on the matrix is to choose any index (x, y) and toggle all the elements between the rectangle having top-left as (0, 0) and bottom-right as (x-1, y-1). Toggling the element means changing 1 to 0 and 0 to 1. The task is to find minimum operations required to make set all the elements of the matrix i.e make all elements as 1.ExampleIf input matrix is {0, 0, 0, 1, 1}    {0, 0, 0, 1, 1}    {0, 0, 0, 1, 1}    {1, 1, ... Read More

Minimum operations to make the MEX of the given set equal to x in C++

Narendra Kumar
Updated on 22-Nov-2019 11:57:49

577 Views

Problem statementGiven a set of n integers, perform minimum number of operations (you can insert/delete elements into/from the set) to make the MEX of the set equal to x (that is given).Note − The MEX of a set of integers is the minimum non-negative integer that doesn’t exist in it. For example, the MEX of the set {0, 2, 4} is 1 and the MEX of the set {1, 2, 3} is 0ExampleIf n = 5 and x = 3 and array is {0, 4, 5, 6, 7} then we require minimum 2 operationsAlgorithmThe approach is to see that in ... Read More

Minimum operations to make XOR of array zero in C++

Narendra Kumar
Updated on 22-Nov-2019 11:57:20

526 Views

Problem statementWe are given an array of n elements. The task is to make XOR of whole array 0. We can do following to achieve this.We can select any one of the element −After selecting element, we can either increment or decrement it by 1.We need to find the minimum number of increment/decrement operation required for the selected element to make the XOR sum of whole array zeroExampleIf arr[] = {2, 4, 7} then 1 operation is required −Select element 2Decrement it by 1Now array becomes {3, 4, 7} and its XOR is 0AlgorithmFind the XOR of whole arrayNow, suppose ... Read More

Minimum partitions of maximum size 2 and sum limited by given value in C++

Narendra Kumar
Updated on 22-Nov-2019 11:24:10

109 Views

Problem statementGiven an array arr[] of positive numbers, find minimum number of sets in array which satisfy following property, A set can contain maximum two elements in it. The two elements need not to be contiguous.Sum of elements of set should be less than or equal to given Key. It may be assumed that given key is greater than or equal to the largest array element.ExampleIf arr[] = {1, 2, 3, 4} and k = 5 then following 2 pairs can be created −{1, 4} and {2, 3}AlgorithmSort the arrayBegin two pointers from two corners of the sorted array. If ... Read More

Minimum Players required to win the game in C++

Narendra Kumar
Updated on 22-Nov-2019 11:19:18

162 Views

Problem statementGiven N questions and K options for each question, where 1

Minimum positive integer value possible of X for given A and B in X = P*A + Q*B in C++

Narendra Kumar
Updated on 22-Nov-2019 11:13:15

189 Views

Problem statementGiven values of A and B, find the minimum positive integer value of X that can be achieved in the equation X = P*A + Q*B, Here P and Q can be zero or any positive or negative integer.ExampleIf A = 2 and B = 4 then answer will be 2.AlgorithmWe need to find P and Q such that P*A > P*B and P*A – P*B is minimum positive integer.This problem can be easily solved by calculating GCD of both numbers)Example#include using namespace std; int getGcd(int a, int b) {    if (a == 0) {     ... Read More

Minimum Possible value of |ai + aj – k| for given array and k in C++

Narendra Kumar
Updated on 22-Nov-2019 11:09:01

243 Views

Problem statementYou are given an array of n integer and an integer K. Find the number of total unordered pairs {i, j} such that absolute value of |ai + aj – k| is minimal possible where i != j.ExampleIf arr[ ] = {0, 4, 6, 2, 4} and k = 7 then we can create following 5 pairs with minimal value as 1{0, 6}, {4, 2}, {4, 4}, {6, 2}, {2, 4}AlgorithmIterate over all possible pairs and for each pair we will check whether the value of (ai + aj – K) is smaller than our current smallest value of ... Read More

Minimum positive integer required to split the array equally in C++

Narendra Kumar
Updated on 22-Nov-2019 11:04:23

221 Views

Problem statementGiven an array of N positive integers, the task is to find the smallest positive integer that can be placed between any two elements of the array such that, the sum of elements in the subarray occurring before it, is equal to the sum of elements occurring in the subarray after it, with the newly placed integer included in either of the two subarraysExampleIf arr = {3, 2, 1, 5, 7, 10} then output is 6. If we place value 6 in between 5 and 7 then sum of left and right subarray becomes equal as follows −+ 2 ... Read More

Advertisements