C++ Articles

Page 77 of 597

Maximum number of ones in a N*N matrix with given constraints in C++

Sunidhi Bansal
Sunidhi Bansal
Updated on 11-Mar-2026 222 Views

Given the task is to find the maximum number of ones in a binary matrix possible with the following constraints.Two integers N and X are given where X

Read More

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

Sunidhi Bansal
Sunidhi Bansal
Updated on 11-Mar-2026 337 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

Maximum number of unique prime factors in C++

Sunidhi Bansal
Sunidhi Bansal
Updated on 11-Mar-2026 1K+ 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

Sum of XOR of all possible subsets in C++

sudhir sharma
sudhir sharma
Updated on 11-Mar-2026 463 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 subarrays in C++

sudhir sharma
sudhir sharma
Updated on 11-Mar-2026 1K+ Views

In this problem, we are given an array arr[] of n numbers. Our task is to create a program to find the sum of XOR of all subarrays of the array.Here, we need to find all sub-arrays of the given array, and then for each subarray, we will find the xor of element and add the XOR value to the sum variable.Let’s take an example to understand the problem, Input: arr[] = {5, 1, 4} Output: Explanation: XOR of all subarrays for the array : XOR {5} = 5 XOR {1} = 1 XOR {4} = 4 XOR {5, 1} ...

Read More

Sum of the series Kn + ( K(n-1) * (K-1)1 ) + ( K(n-2) * (K-1)2 ) + ... (K-1)n in C++

sudhir sharma
sudhir sharma
Updated on 11-Mar-2026 365 Views

In the problem, we are ginen two number k and n of the series K^n + ( K^(n-1) * (K-1)^1 ) + ( K^(n-2) * (K-1)^2 ) + ... (K-1)^n. Our task is to create a program to find the sum of the series.Let’s take an example to understand the problem, Input: n = 3, k = 4 Output: 175 Explanation: Sum of the series is = 4^3 + ( (4^2)*(3^1) ) + ( (4^1)*(3^2) ) + ( (4^0)*(3^3) ) = 64 + 48 + 36 + 27 = 175A simple way to solve the problem, is using a for ...

Read More

Sum of two numbers where one number is represented as array of digits in C++

sudhir sharma
sudhir sharma
Updated on 11-Mar-2026 204 Views

In this problem, we are given two numbers, from which one is represented using array of digits. Our task is to create a program that will find the sum of two numbers where one number is represented as array of digits.Let’s take an example to understand the problem, Input: n = 213, m[] = {1, 5, 8, } Output: 371 Explanation: 213 + 158 = 371To solve this problem, we will simply digit by digit from the number which element of the array. It lsb of the number is added to the (n-1)th element of the array. The carry will ...

Read More

Find two distinct prime numbers with given product in C++

Ayush Gupta
Ayush Gupta
Updated on 11-Mar-2026 199 Views

In this tutorial, we will be discussing a program to find two distinct prime numbers with given product.For this we will be provided with an integer value. Our task is to find the two prime integer values such that their product is equal to the given value.Example#include using namespace std; //generating prime numbers less than N. void findingPrimeNumbers(int n, bool calcPrime[]) {    calcPrime[0] = calcPrime[1] = false;    for (int i = 2; i

Read More

Find trace of matrix formed by adding Row-major and Column-major order of same matrix in C++

Ayush Gupta
Ayush Gupta
Updated on 11-Mar-2026 196 Views

In this tutorial, we will be discussing a program to find trace of matrix formed by adding Row-major and Column-major order of same matrix.For this we will be provided with two arrays one in row-major and other in columnmajor. Our task is to find the trace of the matrix formed by the addition of the two given matrices.Example#include using namespace std; //calculating the calculateMatrixTrace of the new matrix int calculateMatrixTrace(int row, int column) {    int A[row][column], B[row][column], C[row][column];    int count = 1;    for (int i = 0; i < row; i++)       for (int ...

Read More

Queries to update a given index and find gcd in range in C++

Ayush Gupta
Ayush Gupta
Updated on 11-Mar-2026 166 Views

In this tutorial, we will be discussing a program to find queries to update a given index and find gcd in range.For this we will be provided with an array containing integers and Q queries. Our task is to find the result of given queries (updating a given value by X, finding the gcd between two given values).Example#include using namespace std; //getting middle index int findMiddle(int s, int e) {    return (s + (e - s) / 2); } //updating values at given indices void updateIndexValue(int* st, int ss, int se, int i, int diff, int si) { ...

Read More
Showing 761–770 of 5,961 articles
« Prev 1 75 76 77 78 79 597 Next »
Advertisements