Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
C++ Articles - Page 591 of 719
368 Views
Here we will see how to get the median of two sorted array of the same size. We will use C++ STL to store array elements. After getting two arrays, we will merge them into one. As two arrays of same size are merged, then the final array will always hold even number of elements. We need to take two middle elements, then get the average of them for the median.Algorithmmedian(arr1, arr2)Begin arr3 := array after merging arr1 and arr2 sort arr3 len := length of arr3 mid := len/2 median := (arr3[mid] + arr3[mid-1])/2 ... Read More
206 Views
Here we will see one program that will help to check whether a matrix is bisymmetric or not. The Bisymmetric matrix is one square matrix that are symmetric about both of the major diagonals. The below matrix is an example of bisymmetric matrix.1 2 3 4 5 2 6 7 8 4 3 7 9 7 3 4 8 7 6 2 5 4 3 2 1AlgorithmcheckBiSymmetric(mat, n)Begin for i in range 0 to n – 1, do for j in range 0 to i – 1, do if mat[i, j] is ... Read More
586 Views
In this section we will see what are the usage of array::fill() and the array::swap() in C++ STL.The array::fill() function is used to fill the array with some specified value. Let us see one example to get the idea.Example Live Demo#include #include using namespace std; main() { array arr = {00, 11, 22, 33, 44, 55, 66, 77, 88, 99}; cout
129 Views
Here we will see the crbegin() and crend() functions of array in C++ STL.The array::crbegin() function is used to get reverse iterator. It returns constant reverse iterator pointing to the last element of the container. This function does not take any parameter.The array::crend() function is reverse of crbegin(). This returns the iterator which is pointing the last element of the reversed iterator.Let us see some code examples to get better idea.Example Live Demo#include #include using namespace std; main() { array arr = {00, 11, 22, 33, 44, 55, 66, 77, 88, 99}; cout
332 Views
In this section we will see the get() function of array in C++ STL. This function is used to get the ith element of the array container. The syntax is like below −Syntaxget array_nameThis function takes two mandatory parameters. The is the index parameter. It is used to point to the ith position of the array. The second argument is array_name. This is the actual array from this ith element will be taken. This function returns the ith element.Let us see one example to get the idea.Example Live Demo#include #include using namespace std; main() { array arr = {00, 11, ... Read More
2K+ Views
Here we will see about the argument coercion in C or C++. The Argument Coercion is one technique by which the compiler can implicitly convert the arguments from one type to another type. It follows argument promotion rule. If one argument is lower datatype, that can be converted into higher datatypes, but the reverse is not true. The reason is if one higher datatype is converted into a lower datatype, it may loss some data.Let us see one pyramid that can express how the implicit conversion takes place.Example Live Demo#include using namespace std; double myAdd(double a, double b){ return a+b; ... Read More
314 Views
In this problem, we need to generate all reverse permutations of a given array using C++'s Standard Template Library (STL). A permutation is simply rearranging the elements of the array in every possible order. For example, with an array of three elements, there are six possible ways to arrange them. For each of these permutations, we need to reverse the order of the elements and then print the results. The goal is to first generate all possible permutations of the array, then reverse each one before displaying them. Example Scenario: Let's say we have the array {1, 2, 3}. ... Read More
273 Views
Here we will see how to calculate the remainder of array multiplication after dividing the result by n. The array and the value of n are supplied by the user. Suppose the array is like {12, 35, 69, 74, 165, 54} so the multiplication will be (12 * 35 * 69 * 74 * 165 * 54) = 19107673200. Now if we want to get the remainder after diving this by 47 it will be 14.As we can see this problem is very simple. we can easily multiply the elements then by using modulus operator, it can get the result. ... Read More
676 Views
In this section we will see how we can get the product of unique prime factor of a number in an efficient way. There is a number say n = 1092, we have to get product of unique prime factors of this. The prime factors of 1092 are 2, 2, 3, 7, 13. So the unique prime factors are {2, 3, 7, 13}, the product is 546. To solve this problem, we have to follow this rule −When the number is divisible by 2, then multiply 2 with product, and divide the number by 2 repeatedly, then next 2s will ... Read More
532 Views
Here we will see how the brick sort works. The Brick sort is one modification of bubble sort. This algorithm is divided into two parts. These parts are odd part and even parts. In the odd part we will use the bubble sort on odd indexed items, and in the even part we will use the bubble sort on even indexed elements. Let us see the algorithm to get the idea.AlgorithmbrickSort(arr, n)begin flag := false while the flag is not true, do flag := true for i := 1 to n-2, increase ... Read More