Found 7347 Articles for C++

C++ Return Previous Element in an Expanding Matrix

Prateek Jangid
Updated on 26-Nov-2021 07:23:15

122 Views

Discuss a problem based on expanding the matrix. Expanding matrix is a matrix whose size continuously increases by some factor.Here we have a matrix of characters whose size is expanding by a factor of 2, i.e., if the original size of the matrix is N * N, then the size of the expanded matrix becomes 2N * 2N. We are given a sequence of characters present at ( i, j ), and we need to return the sequence of characters present at (i, (j - N - 1)%N).Let’s understand by visualizing some initial expanded matrix, Given Matrix -> [ a, ... Read More

Restoring Division Algorithm For Unsigned Integer in C++

Prateek Jangid
Updated on 26-Nov-2021 07:10:19

1K+ Views

Discuss dividing an unsigned integer using a division algorithm. Some division algorithms are applied on paper, and others are implemented on digital circuits. Division algorithms are of two types: slow division algorithm and fast division algorithm. Slow division algorithm includes restoring, non-performing restoring, SRT, and non-restoring algorithm.In this tutorial, we will discuss the Restoring algorithm, assuming that 0 < divisor < dividend.Approach to Find the SolutionIn this, we will use register Q to store quotient, register A to store remainder, and M to store divisor. The initial value of A is kept at 0, and its value is restored, which ... Read More

Find the Pairs of Positive Negative values in an Array using C++

Prateek Jangid
Updated on 26-Nov-2021 07:14:42

281 Views

In this article, we have an array containing distinct elements. We need to print the pairs of positive-negative values in the array with the same absolute value and print them in sorted order for examples −Input : arr[] = { 1, -1, 11, 12, 56, 77, -56, -12, -88} Output : -1 1 -12 12 -56 56 Input : arr[] = {30, 40, 50, 77, -51, -50, -40} Output : -40 40 -50 50Approach to find The SolutionThe first approach that comes to our mind is the Brute Force approach, and we make up another one called the Efficient ... Read More

Find the Pair with a Maximum Sum in a Matrix using C++

Prateek Jangid
Updated on 26-Nov-2021 07:04:09

175 Views

In this article, we will discuss finding a pair with a maximum sum in a given matrix or 2-D array. For exampleInput : matrix[m][n] = {    { 3, 5, 2 },    { 2, 6, 47 },    { 1, 64, 66 } } Output : 130 Explanation : maximum sum is 130 from element pair 64 and 66. Input : matrix[m][n] = {    { 55, 22, 46 },    { 6, 2, 1 },    { 3, 24, 52 } } Output : 107 Explanation : maximum sum is 130 from element pair 55 and ... Read More

Find the Pair with Given Sum in a Matrix using C++

Prateek Jangid
Updated on 26-Nov-2021 06:59:43

191 Views

In this article, we will discuss the program of finding a pair with a given sum in a given matrix. For example −Input : matrix[n][m] = {    { 4, 6, 4, 65 },    { 56, 1, 12, 32 },    { 4, 5, 6, 44 },    { 13, 9, 11, 25 } }, SUM = 20 Output : Pair exists. Explanation : Sum = 20 is equal to the sum of numbers 9 and 11 which exists in the matrix. Input : matrix[n][m] = {    { 5, 7, 3, 45 ... Read More

C++ Representation of a Number in Powers of Other

Prateek Jangid
Updated on 26-Nov-2021 06:53:38

176 Views

Discuss the problem of representing a number in the power of another number. We are given two numbers, x, and y. We need to tell whether y can be represented in the power of x where each power of x can be used once, for exampleInput: x = 4, y = 11 Output: true Explanation: 4^2 - 4^1 - 4^0 = 11 Hence y can be represented in the power of x. Input: x = 2, y = 19 Output: true Explanation: 2^4 + 2^1 + 2^0 =19 Hence y can be represented in the power of x. ... Read More

Represent a Number as Sum of Minimum Possible Pseudo-Binary Numbers in C++

Prateek Jangid
Updated on 26-Nov-2021 06:46:41

406 Views

This tutorial will discuss the representation of a number as a sum of minimum pseudo-binary numbers. Pseudo-binary numbers are the numbers that consist of only binary digits, i.e., 0 and 1. Examples of pseudo-binary numbers are 00, 11, 10, 100, 111, 1011, etc.Below are some examples of numbers represented as the sum of pseudo-binary numbers.Input : 23 Output : 11 + 11 + 1 Explanation : 23 = 11 + 11 + 1, sum of pseudo-binary numbers(11, 11, 1) is 23. Input : 50 Output : 10 + 10 + 10 + 10 + 10Approach to Find the SolutionBelow ... Read More

Represent a number as a Sum of Maximum Possible Number of Prime Numbers in C++

Prateek Jangid
Updated on 26-Nov-2021 06:43:01

175 Views

Discuss a problem where we are given a number N, and we need to split this number in the maximum prime numbers sum, for exampleInput: N = 7 Output: 2 2 3 Explanation: 7 can be represented as the sum of two 2’s and a 3 which are the maximum possible prime numbers. Input : N = 17 Output: 2 2 2 2 2 2 2 3Approach to Find the SolutionTo represent a number in prime numbers, we can subtract a prime number with N and check the difference for prime. If the difference is prime, then we can ... Read More

Find the Numbers that are not divisible by any number in the range [2, 10] using C++

Prateek Jangid
Updated on 26-Nov-2021 06:51:33

639 Views

In this article, we will discuss the problem to find the numbers from 1 to n(given) which are can not be divided by any number from 2 to 10. Let's understand this with some examples −Input : num = 14 Output : 3 Explanation: There are three numbers, 1, 11, and 13, which are not divisible. Input : num = 21 Output : 5 Explanation: There are five numbers 1, 11, 13, 17, and 19, which are not divisible.Approach to find The SolutionSimple ApproachIf we check every number from 1 to num, whether it can be divided by any ... Read More

Represent a Given Set of Points by the Best Possible Straight Line in C++

Prateek Jangid
Updated on 26-Nov-2021 06:40:23

337 Views

Discuss How to represent a set of points by the best possible straight line. We are given values (x, y) of a set of points, and we need to find the best straight line y = mx + c, So all we need is to find the value of m and c, for exampleInput: no_of_points = 4 x1 = 2, y1 = 3, x2 = 5, y2 = 6, x3 = 1, y3 = 3, x4 = 4, y4 = 5. Output: m = 0.8, c = 1.85 Explanation: If we apply the value of m and c in ... Read More

Advertisements