
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
Found 7197 Articles for C++

225 Views
We need to compute sum of elements from index i to index j. The queries consisting of i and j index values will be executed multiple times.Input:arr[] = {5, 6, 3, 4, 1 } i = 1, j =3 Output: 13Explanation6 + 3 + 4 = 13 sum[] = {5, 6+5, 3+6+5, 4+3+6+5, 1+4+3+6+5 } sum[]={5, 11, 14, 18, 19} sum[j]-sum[i-1]=sum[3]-sum[1-1]= sum[3]-sum[0]=18-5=13The logic is very basic in this starting the loop form i index to till j index and sum up the elements between those indexes. But we can’t store them in extra variable so we will use another array ... Read More

168 Views
Two integers X and K are given. K is the number of digit in integer number. The logic is to find largest K-digit number divisible by X.Input: X = 30, K = 3 Output: 980Explanation980 is the largest three digit number divisible by 30. By taking the K in power of 10 then subtracting it with 1 will give us the largest K digit number after that we will try to get the largest no. which is divided by X.Example#include #include using namespace std; int main() { int X = 20; int K = 3; int MAX = pow(10, K) - 1; cout

220 Views
Gnome sort is a sorting algorithm which is similar to Insertion sort, except that moving an element to its proper place is accomplished by a series of swaps, as in bubble sort.Input: 53421 Output: 12345ExplanationSorting algorithm that moving an element to its proper place is accomplished by a series of swaps, as in bubble sort. It is simply requiring loops.Example#include using namespace std; int main() { int temp; int arr[] = { 5, 3, 4, 2, 1 }; int n=5; int i; i = 0; while (i < n) { if (i == 0 || arr[i - 1]

2K+ Views
The common divisor of two numbers are the numbers that are divisors of both of them.For example, the divisors of 12 are 1, 2, 3, 4, 6, 12. The divisors of 18 are 1, 2, 3, 6, 9, 18. Thus, the common divisors of 12 and 18 are 1, 2, 3, 6. The greatest among these is, perhaps unsurprisingly, called the of 12 and 18. The usual mathematical notation for the greatest common divisor of two integers a and b are denoted by (a, b). Hence, (12, 18) = 6.The greatest common divisor is important for many reasons. For example, ... Read More

528 Views
Comb sort is similar to bubble sort and cocktail sort. Comb sort doesn’t start off looking at adjacent elements but instead looks at elements a certain number of indexes apart, this is called the gap. The gap is defined as [n/c] where n is the number of elements and c is the shrink factor. After each iteration, this number is against divided by c and floored until eventually, the algorithm is looking at adjacent elements.Input:53421 Output:12345ExplanationComb sort compare two elements with a gap which is defined as [n/c] where n is the number of elements and c is the shrink ... Read More

2K+ Views
What are Common Divisors? The common divisors of two numbers are the numbers that are divisors of both. A number is said to divide another number if it leaves no remainder when divided. For example, 3 divides 12 since 12 / 3 = 4 (no remainder). But 5 does not divide 12 because 12 / 5 = 2 with a remainder of 2. Understanding with an Example Let’s take two numbers, 12 and 18. We list all the divisors of both numbers and identify the common ones. ... Read More

306 Views
Cocktail sort is a variation of bubble sort that is both a stable sorting algorithm and a comparison sort also known as bidirectional bubble sort, cocktail shaker sort, shaker sort (which can also refer to a variant of selection sort), ripple sort, shuffle sort, or shuttle sort. The algorithm differs from a bubble sort in that it sorts in both directions on each pass through the list.Input:53421 Output:12345Explanation In Cocktail, sort array will be consist of the unsorted element. Cocktail sort works in both directions on each pass through the list. It sort array using bubble sorts once forwards and backward.Example#include ... Read More

847 Views
Bogosort simply shuffles a collection randomly until it is sorted. BogoSort is an ineffective algorithm based permutation and combination that's why it is known Permutation sort. BogoSort is very flop sorting technique which is also known as, shotgun sort, stupid sort, monkey sort, or slow sort. The algorithm successively generates permutations of its input until it finds one that is sorted.Input - 53421 Output - 12345ExplanationIn bogosort array will be consist of unsorted element checking if the array elements are in order, and if it is not, then change the position of array elements, by swapping the elements randomly, and ... Read More

133 Views
The acosh() is the inverse hyperbolic cosine function that returns the inverse hyperbolic cosine of the element passed as parameter. this dysfunction can be out operate over complete. all the it are in radians.To use this method over complex numbers in C plus plus we need to define a template which redefines the function over complex numbers.Syntax for the function that is used to calculate the inverse hyperbolic cosine of a complex number and Returns the value −template complex acosh (const complex& z );Now this method will take complex number as an input and returns the Arc hyperbolic cosine of ... Read More

124 Views
The asinh() function is a function of standard C++ library. The asinh(value) is an inverse hyperbolic sine that returns the value of sinh(x) where x is in radian.The function −asinh() ;Parameter to the function, inverse hyperbolic angle in radian . It can be negative, positive or zero. The parameter value can be double, float or long double.Return value − It returns the inverse hyperbolic sine value of the input value. The returned value is in radians.Lets see an example that shows the working of the function −Example#include using namespace std; int main() { double insinh = 75.0; double ... Read More